对alias配置的目的是为了减少后续引用路径的复杂性。
配置的方式为:
// 在vue.config.js文件中
const path = require('path')
function resolve(dir) {
return path.join(__dirname, dir)
}
module.exports = {
configureWebpack: {
// provide the app's title in webpack's name field, so that
// it can be accessed in index.html to inject the correct title.
name: name,
resolve: {
alias: {
'@': resolve('src')
}
}
}
在后续需要引用路径src时,只需要将src替换成@。比如要引用src/api/stickTop.js,
import { stickTop } from '@/api/stickTop'