解决 VSCode 的模块导入别名问题

2021-07-29 14:48:09 浏览数 (2)

添加jsconfig.json

代码语言:javascript复制
{
  "compilerOptions": {
    "target": "es2015",
    "baseUrl": "./src",
    "paths": {
      "@api/*": ["api/*"],
      "@common/*": ["common/*"],
      "@components/*": ["components/*"],
      "@doc/*": ["../doc/*"],
      "@domain/*": ["domain/*"],
      "@router/*": ["router/*"],
      "@model/*": ["domain/model/*"],
      "@service/*": ["domain/service/*"],
      "@store/*": ["store/*"],
      "@utils/*": ["utils/*"],
      "@views/*": ["views/*"],
    },
    "allowSyntheticDefaultImports": true
  },
  "exclude": ["node_modules", "dist"]
}
  • 注意下*,之前没加没有生效
  • exclude 可以加速

paths配置alias,这样就可以在代码里使用alias

代码语言:javascript复制
import createRouter from '@/router';
import store from '@/store';

0 人点赞