第一张方法
小编是在项目的vue.config.js中配置的,代码如下图所示:
//安装path模块
const path = require("path");
function resolve(dir) {
return path.join(__dirname, dir);
}
module.exports={
devServer:{},
chainWebpack: (config) => {
config.resolve.alias
.set("@", resolve("src"))
.set("@u", resolve("src/utils"));
},
}
第二种方法
const path = require("path");
function resolve(dir) {
return path.join(__dirname, dir);
}
module.exports = {
lintOnSave: process.env.NODE_ENV === "development",
configureWebpack: {
name: name,
resolve: {
alias: {
"@": resolve("src"),
"@i": resolve("src/api"),
"@c": resolve("src/components"),
"@v": resolve("src/pages"),
"@s": resolve("src/static"),
"@u": resolve("src/utils")
}
}
}
};