【发布时间】:2020-10-11 12:28:24
【问题描述】:
我正在创建一个从 Deezer Api 获取数据的 React 应用程序
目前,我正在尝试获取热门专辑https://api.deezer.com/chart/0/tracks:
我创建了一个请求数据的函数
fetchTopAlbums = () => {
return fetch('https://api.deezer.com/chart/0/tracks', { 'Accept': 'application/json', })
.then((res) => res.json())
}
在调用此函数时,我在控制台中收到此错误
Access to fetch at 'https://api.deezer.com/chart/0/tracks' from origin 'http://localhost:3000' 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.
【问题讨论】:
-
你为什么不研究一下什么是 cors。
-
你需要添加cors到你的服务器
标签: javascript reactjs api fetch restful-authentication