首页 > 移动平台 > 详细

vue axios 配置上服务器后报错'Access-Control-Allow-Origin' header]

时间:2019-08-28 16:23:22      阅读:277      评论:0      收藏:0      [点我收藏+]

ue项目配置到服务器后,请求能够成功,返回的数据也能在浏览器中看见,但是报错:

Failed to load http://pre.api.jmxy.mockuai.c...: The value of the ‘Access-Control-Allow-Origin‘ header in the response must not be the wildcard ‘*‘ when the request‘s credentials mode is ‘include‘. Origin ‘http://pre.promotion.jmxy.moc...‘ is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

技术分享图片

请求状态码为200. 在浏览器中也能看到返回的数据:

我配置的axios为:

 
var instance = axios.create({
  baseURL: baseUrl,
  timeout: 1000 * 12, // 创建axios实例,设定超时时间是12s
  withCredentials: true, // 允许携带cookie
  headers: {
    "Content-Type": "application/x-www-form-urlencoded;charset=utf-8"
  }
});

解决方法:

withCredentials: false, // 允许携带cookie

在axios里把这一条设置为false就行了,我们的项目是不需要携带cookie的,所以之前的项目后端都没有改过,我刚接手,所以不太清楚,才闹出这个问题,如果需要携带cookie的话,我搜了一圈下来,基本上都和下面几位的回答的是一样的,需要后端配置。

 

vue axios 配置上服务器后报错'Access-Control-Allow-Origin' header]

原文:https://www.cnblogs.com/braveLN/p/11424710.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!