Access to XMLHttpRequest at 'https://api-v3.igdb.com/games/?search=nfs&fields=name,genres.name,first_release_date,cover.*&limit=10&offset=0' from origin 'http://localhost:3000' 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.
我不明白如何解决这个错误。
我需要 localhost:3000 中的跨源帮助
显示这样的代码:
var headers = {'user-key': '**********************',
'Accept': 'application/json',
"Access-Control-Allow-Methods": "GET, POST, PATCH, PUT, DELETE, OPTIONS",
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization',
'Access-Control-Allow-Credentials': true
}
var dataurl = 'https://api-v3.igdb.com/games/?search=nfs&fields=name,genres.name,first_release_date,cover.*&limit=10&offset=0'
axios.post( dataurl, '' , { crossDomain: true,headers:headers })
.then(resData => {
console.log(resData)
})
.catch(err =>{
console.error(err)
})