vue-cli axios跨域

关于vue-cli使用axios的跨域问题
我卡了半个小时,就是很多细节撒花姑娘没有处理好造成的
下面贴代码
proxyTable: {
‘/index’:{
target:’ ‘,
changeOrigin:true,
pathRewrite:{
‘^/index’: ‘/index’
}
}
},
在config里的index.js里找到proxyTable配置
target写上你的api域名地址
changeOrigin等于true是允许跨域
下面的pathRewrite是替换的
this.$http({
method:‘get’,
url:’’,
}).then(function(res){
console.log(res.data.data)
}).catch(function(err){
console.log(err)
})
url只要写上api就可以了
希望可以帮助到大家!有什么看了有深入理解的大佬们,看到还请指定一二

猜你喜欢

转载自blog.csdn.net/weixin_43860135/article/details/85342146