C/C++教程

Uniapp---报has been blocked by CORS policy:错误【解决办法】

本文主要是介绍Uniapp---报has been blocked by CORS policy:错误【解决办法】,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

最近在用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' 
},

打完收工!

这篇关于Uniapp---报has been blocked by CORS policy:错误【解决办法】的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!