First put the project under index.js config file to find out,
See if have written proxy, for example:
proxyTable: {// probably like 13 lines of the current document ha '/ API' : { target: 'HTTP: // xxxxxxxx' , // call interface domain name and port number Ha changeOrigin: to true , pathRewrite: { '^ / API ':' / API ' } } }
Error Scene One:
Access to XMLHttpRequest at 'xxxxx' from origin 'xxx' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Error Scene Two:
Access to XMLHttpRequest at 'xxxx' from origin 'xxx' has been blocked by CORS policy:Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.
Both are currently experiencing are related to the relevant back-end, back-end need to deal with what you can.
//配置请求
const baseUrl = 'xxxxx';
const options = {};
const url = baseUrl +'/api';
const params = {
'userPhone':'xxx'
}
options.method = 'post';
options.mode = 'no-cors';
options.body = JSON.stringify(params);
options.headers = {
'Content-Type':'application/json'
}
return fetch(url,options,{credentials:'include'}).then(res=>{}).catch(err=>{})
链接地址: https://www.cnblogs.com/mryaohu/p/12483757.html