编辑vue.config.js文件
module.exports={
devServer:{
proxy:{
'/test':{
target:'http://localhost:7002',
changeOrigin: true,
secure: false,
pathRewrite: {
'^/test': ''
}
}
}
}
}
这样每次
axios.get('/test')
.then(res=>{
console.log(res);
})
请求/test的地址就会变成 http:localhost:7002
本文介绍如何通过编辑vue.config.js文件设置代理,将axios请求的/test路径重定向到http://localhost:7002,实现跨域解决方案。

被折叠的 条评论
为什么被折叠?



