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

添加jsconfig.json

{
  "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

import createRouter from '@/router';
import store from '@/store';
posted @ 2021-07-27 18:33  JadePeng  阅读(80)  评论(0编辑  收藏  举报