vue跨域请求解决方案
在config/index.js文件中如下配置:
proxyTable: {
"/api":{
target:"http://127.0.0.1:8001",
changeOrigin:true,
pathRewrite:{
'^/api':''
}
}
proxyTable中配置如上。
"/api"是自定义的接口名称,映射到http://127.0.0.1:8001这个接口。配置完之后,在项目中再访问该接口时可以访问项目url/api即可。
如下我通过本地url(8080端口请求8001是跨域请求)请求已经做过映射的api的接口。
axios
.get('http://127.0.0.1:8080/api')
.then(response => (this.msg = response.data.getter))
.catch(error => console.log(error))

9264

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



