资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

Vue.js中axios跨域访问错误问题及解决方法-创新互联

1、假如访问的接口地址为 http://www.test.com/apis/index.php  (php api 接口)

创新互联建站是专业的镇雄网站建设公司,镇雄接单;提供成都网站设计、成都网站制作、外贸网站建设,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行镇雄网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

2、而开发地址为http://127.0.0.1:8080,当axios发起请求时,出现如下错误:

Failed to load http://www.test.com/apis/index.php?&act=login: The value of the 'Access-Control-Allow-Origin' headerin the response must not be the wildcard '*' when the request's credentials mode is 'include'. Origin 'http://127.0.0.1:8080' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

解决方法:


1、修改config/index.js, 修改 proxytable

proxyTable: {
 '/apis': {
   target: 'http://www.test.com/apis/', // 接口地址
   changeOrigin: true, 
   pathRewrite: {
     '^/apis': ''  //需要rewrite重写的,
   }       
 }
},

标题名称:Vue.js中axios跨域访问错误问题及解决方法-创新互联
分享网址:http://cdkjz.cn/article/cdpish.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220