需求是我们这边系统中功能用到两个不同的接口,需要做不同的页面处理,因此考虑配置多个地址,同时解决跨域问题。配置proxyTable,解决跨域问题。如下图所示:
页面请求:
this.$axios.post('/api/weblogin/login',data).then(res=>{
console.log(res)
})
后面遇到需要连接不同的接口域名,我在proxyTable里增加了一个apiGas。axios请求存在获取得到api但是不能获取apiGas(提示请求资源不存在)。
proxyTable: {
'/api': {
target: 'http://', // 接口域名
changeOrigin: true, //是否跨域
pathRewrite: {
'^/api': '/bsgzf/api/auth/' , //需要rewrite的,
},
},
'/apiGas': {
target: 'http://', // 接口域名
changeOrigin: true, //是否跨域
pathRewrite: {
'^/apiGas':'/bsgzf/api/gas/'
}
},
},
查找了很多资料都没有具体的解决方法,看到有提到顺序的问题,让把这两个链接位置换一下,抱着试一试的态度换了,重新运行,结果两个都可以获取了。如图:
proxyTable: {
'/apiGas': {
target: 'http://', // 接口域名
changeOrigin: true, //是否跨域
pathRewrite: {
'^/apiGas':'/bsgzf/api/gas/'
}
},
'/api': {
target: 'http://', // 接口域名
changeOrigin: true, //是否跨域
pathRewrite: {
'^/api': '/bsgzf/api/auth/' , //需要rewrite的,
},
},
},