问题描述
uni-app 前端请求后端数据时候出现错误
Access to XMLHttpRequest at 'http://localhost:8002/bmft/jingdong/list/java'
from origin 'http://localhost:8080' has been blocked by CORS policy:
Response to preflight request doesn't pass access control check:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
request doesn’t pass access control check
这是不允许跨域请求的原因
解决方法
SpringBoot解决跨域请求的方法(其他请自行百度十分简单)
给controller加上注解 @CrossOrigin("http://localhost:8080")
例如