首先需要创建一个
vue.config.js
const path = require('path'); // 引入路径
function resolve(dir) {
return path.join(__dirname, dir)
}
module.exports = {
publicPath: './',
devServer: {
proxy: ``
},
lintOnSave: false,
chainWebpack: (config) => {
config.resolve.alias
.set('#', resolve('public'))
.set('@c', resolve('src/components'))
.set('@a', resolve('src/assets'))
.set('@v', resolve('src/views'))
}
}
这个时候在文件里写简写路径已经可以找到,如果控制台会报错,Cannot find module
tsconfig.json 里添加
"paths": {
"@/*": [
"src/*"
],
"@c/*": [
"src/components/*"
],
"@v/*": [
"src/views/*"
],
"@a/*": [
"src/assets/*"
],
"#/*": [
"public/*"
]
},