【发布时间】:2020-09-19 13:01:26
【问题描述】:
我使用 fetch() 登录它工作正常,但是当我想使用 axios 它返回失败并抛出错误 from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource 。我想用 axios 替换 fetch() 数据,有人可以帮我吗
(async () => {
const rawResponse = await fetch(`https://cors-anywhere.herokuapp.com/${config.apiPath}/login`, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({ email: data.email, password: data.password })
});
const content = await rawResponse.json();
console.log(content);
})()
【问题讨论】:
-
使用
axios向我们展示代码 -
我要转成axios
-
服务器是否启用了
cors? -
是的............
-
可能是服务端配置不正确,这个错误与客户端无关。
标签: javascript reactjs axios fetch