最近在用Uniapp开发项目,一直都是好好。但是突然报了一个神奇的错误:
Access to XMLHttpRequest at 'http://xxxx.xxxx.com/addons/Paper/api/v1/papers?is_over=false&loading=true&page=1&size=10' from origin 'http://127.0.0.1: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.
具体解决:
'Access-Control-Allow-Origin: *' 'Access-Control-Allow-Headers: Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With'
前端:需配置请求头
header: { 'content-type':'application/x-www-form-urlencoded' },
打完收工!