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

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.

clipboard.png

请求状态码为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的话,我搜了一圈下来,基本上都和下面几位的回答的是一样的,需要后端配置。

 

转载于:https://www.cnblogs.com/braveLN/p/11424710.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值