VUE解决跨域
2020-09-15 本文已影响0人
MaJiT
1.vue.config.js 修改
proxyTable: {
'/apis':{
target: 'http://127.1.1.1:2000, //A服务器地址
changeOrigin: true, //改变源路劲
pathRewrite: {
'^/apis': '/'
}
},
'/common':{
target: 'http://127.1.1.1:1000', //B环境的数据
changeOrigin: true, //改变源路劲
pathRewrite: {
'^/common': '/'
}
}
},
2.使用
this.$axios({
url: '/apis/user/login', // '/common/user/login',
method: 'get',
}).then(res => {
console.log('success');
}).catch({
console.log('error');
})
});