场景:不同的接口使用不同的代理地址
eg:
dev.js文件
const url='/api'
const regulationUrl='/regulation'//新配置的
const proxyBackUrl='http://xx.xx.xx.x:8080'
const proxyBackUrl1='http://xx.xx.xx.x:8090'//新配置的
const proxyBackUrl='http://opsol-core-opsol-ygt.fat001.xx.xxx.com.cn/opsol';//a菜单使用的代理api
const proxyBackUrl1='http://opsol-core-opsol-ygt.fat001.xx.xxx.com.cn/regulation';//b菜单使用的代理regulation //新配置的
module.exports={
EnvConfig:{
NODE_ENV:'development',
APP_TITLE:'本地开发环境',
API_HOST:url,
API_HOST_1:regulationUrl
},
//与vue-cli进行合并
webpackConfig:{
devServer:{
//open:false,//项目启动时是否自动打开浏览器,false不打开 true打开
port:2356,//在这里修改端口号
proxy:{
[url]:{
target:proxyBackUrl,
changeOrigin:true,//是否跨域
//ws:true,
//secure:false,//如果是https接口,需要配置这个参数
pathRewrite:{//重写路径
['^'+url]:''
}
},
[regulationUrl]:{//新配置的
target:proxyBackUrl1,
changeOrigin:true,
pathRewrite:{
['^'+regulationUrl]:''
}
}
}
}
}
}
记录:生产环境和测试环境需要接口域名去配置跨域