前端Vue 项目数据请求跨域问题:The value of the ‘Access-Control-Allow-Origin‘ header in the response must not be t

11 篇文章 0 订阅
2 篇文章 8 订阅

 1. 报错问题

console报错如下:

Access to XMLHttpRequest at 'https://xxxxxx/system/users?totalPages=1&totalCount=1&page=1&name=&realName=&roleId=&m
obile=&sex=&email=' from origin 'http://localhost:8080' has been blocked by CORS policy: 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'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

'访问XMLHttpRequest'https://xxxxxxxx/system/users?totalPages=1&totalCount=1&page=1&name=&realName=&roleId=&m
obile=&sex=&email='来源'http://localhost:8080'已被CORS策略阻止:当请求的凭据模式为'include'时,响应中'Access Control Allow Origin'标头的值不能是通配符'*'。XMLHttpRequest发起的请求的凭据模式由withCredentials属性控制。

我寻思前端项目也没设置啥的,它就死坑给我报这个错,后面估计是前后端设置不一致的问题导致

2. 解决办法:

 给axios 设置:

axios.defaults.withCredentials = false;

就没有跨域报错了,成功请求到数据:

 

感谢,从于vue开发的前端跨域问题Access-Control-Allow-Origin 这篇文章了解到:

  1.  当前端配置withCredentials=true时, 后端配置Access-Control-Allow-Origin不能为*, 必须是相应地址
  2. 当配置withCredentials=true时, 后端需配置Access-Control-Allow-Credentials
  3. 当前端配置请求头时, 后端需要配置Access-Control-Allow-Headers为对应的请求头集合

  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值