分类 HTTP 下的文章

fetch 引发 blocked by CORS policy


起步

当使用 fetch 函数做跨域请求时,大概率会在浏览器 Console 中看到这样一个错误信息:Access to fetch at 'xxx' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.