Vue-cli3x路径别名的使用

根目录下vue.confing.js

const path = require('path')

function resolve(dir) {
    return path.join(__dirname, dir)
}

module.exports = {
    publicPath: './',
    chainWebpack: (config) => {
        config.resolve.alias
            .set('@$', resolve('src'))
            .set('@api', resolve('src/api'))
            .set('@util', resolve('src/util'))
            .set('@assets', resolve('src/assets'))
            .set('@comp', resolve('src/components'))
            .set('@config', resolve('src/config'))
            .set('@views', resolve('src/views'))
            .set('@static', resolve('src/static'))
            .set('@public', resolve('public'))
    }
}

js中引用

// src/api/login.js
import login from '@api/login'

html中引用

//前面加~
<img src="~@public/images/user.png" alt="">