Vue+Springboot 跨域问题:Access-Control-Allow-Origin

本文探讨了在Vue和Springboot前后端分离项目中遇到的跨域问题,详细介绍了错误信息及其原因。重点讲解了@CrossOrigin注解的使用限制,即与前端的withCredentials=true不兼容,并提供了两种解决跨域问题的方法:一是通过调整前端withCredentials的设置,二是通过全局配置CORS。最后解释了CORS的原理,强调了Access-Control-Allow-Origin头部在跨域策略中的关键作用。
摘要由CSDN通过智能技术生成

异常: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.

前提:SpringBoot+Vue前后端分离的项目,前端post请求后端数据,前端后端端口不同,为了使前端能请求到后端的数据配置跨域。

 

1.前端:查看vue中有没有设置  withCredentials=ture

 

2.后端:springboot可直接使用注解@CrossOrigin,如图,也设置了跨域

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值