答案 0 :(得分:7)
尝试创建jsconfig.json并配置paths
编译器选项
{
"compilerOptions": {
"baseUrl": ".",
"module": "commonjs",
"paths": {
"@cmp/*": ["./src/components/*"]
}
}
}
您可以找到有关paths
和其他编译器选项here
答案 1 :(得分:2)
这对我有效,如建议here(我希望@/
解析为./src/
):
{
"compilerOptions": {
"target": "es2017",
"allowSyntheticDefaultImports": false,
"baseUrl": "./",
"paths": {
"@/*": ["src/*"],
}
},
"exclude": ["node_modules", "dist"]
}
最低版本,但我也会离开exclude
:
{
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@/*": ["src/*"]
}
},
}