今天在学习vue的时候,简单的做了一个前后端分离的测试,
通过axios请求本地项目的内容时报错:
Failed to load http://localhost:8082/XXXX: No 'Access-Control-Allow-Origin' header is present on the requestedresource. Origin 'http://localhost:8082' is therefore not allowed access.If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
直接翻译:
加载失败http://localhost/本地主机:8082/XXXX号:
请求的上不存在“Access Control Allow Origin”头
资源。起源’http://localhost/本地主机:8082’因此不允许访问。
如果不透明的响应满足您的需要,请将请求的模式设置为“否”-
cors’来获取禁用cors的资源。
可能是因为两个原因引起,一个是响应头,一个是cors设置,
解决办法很简单,直接在controller上加
@CrossOrigin