vue.config.js 中找到 devServer 中的 proxy 配置如下:
devServer: {
port: port,
open: true,
overlay: {
warnings: false,
errors: true
},
proxy: {
[process.env.VUE_APP_BASE_API]: {
target: 'http://api.com/', // 当前地址为接口地址
changeOrigin: true,
pathRewrite: {
['^' + process.env.VUE_APP_BASE_API]: ''
}
}
// before: require('./mock/mock-server.js')
}
},
开发环境:.env.development 文件 设置 VUE_APP_BASE_API 为空:
# just a flag
ENV = 'development'
# base api
VUE_APP_BASE_API = ''
线上环境:.env.production 文件 设置 VUE_APP_BASE_API 为:
# just a flag
ENV = 'production'
# base api
VUE_APP_BASE_API = 'http://api.com/'