vue.js - Vue.Js:别名配置
问题描述
我正在尝试为我的 Vue.js 项目中的components
和sub-directories
使用创建别名。jsconfig.json
但我收到此错误:
jsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@components/*": [
"./src/components/*"
],
}
},
"exclude": [
"node_modules"
]
}
一些文件.vue
import GuestLayout from '@components/Layouts/GuestLayout';
错误:
ERROR Failed to compile with 1 error
...
To install it, you can run: npm install --save @components/Layouts/GuestLayout
我尝试解决这个问题,但似乎没有任何效果。这是找到的最简单的https://www.youtube.com/watch?v=U73TDohXmhQ
我在这里做错了什么..?
解决方案
✔ 问题解决:
对我有用的是设置配置vue.config.js
而不是使用jsconfig.json
or tsconfig.json
。
vue.config.js
const path = require('path');
module.exports = {
configureWebpack: {
resolve: {
alias: {
'@Layouts': path.resolve(__dirname, 'src/components/Layouts/'),
'@Inputs': path.resolve(__dirname, 'src/components/Input/'),
'@': path.resolve(__dirname, 'src/components/'),
}
}
}
}
一些文件.vue
import GuestLayout from '@Layouts/GuestLayout';
import FormGroup from '@Inputs/FormGroup';
...
推荐阅读
- database - 当 db 在 diff (27020) 端口中创建时,无法从 robo3T 访问 mongodb 集合。(能够连接到 db 但不能连接到 coll)
- mysql - 有没有办法限制 IN 子句中每个元素的行数?
- c - 在 Windows 上使用 Cygwin64 编译器和调试器为 C 设置 VS Code(错误:无法开始调试)
- r - foreach %dopar% 到 sparklyr 中?
- javascript - 如何在打字稿中使用条件导入模块的类型?
- python - 如何在python中的if ... else语句中编写if else?
- r - 在 dplyr 中删除具有特定列值的行
- liquid - 如何在 Liquid 中执行重复的产品条件?
- java - 我想用给定的用户输入创建一个数组的条形图
- python - 当其他数组为 NaN 时,Python 2D 数组将值替换为 NaN