第一步:安装一下path
npm install path --save
第二步:在vue.config.js文件中配置一下
const path = require('path')function resolve(dir) {return path.join(__dirname, dir)
}
module.exports = {chainWebpack: config => {config.resolve.alias.set("@", resolve("src")) .set("assets", resolve("src/assets")).set("components", resolve("src/components")).set("base", resolve("baseConfig")).set("public", resolve("public"));},configureWebpack: {resolve: {alias: {'@': resolve('src') //配置根目录的@方法}}},
}