接收没有'Access-Control-Allow-Origin'标头出现在请求的资源上,带有axios get请求

时间:2018-06-09 16:12:53

标签: cors axios

我正在使用以下请求:

axios.get('https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=43.2502078,13.513169&radius=1500&type=restaurant&keyword=cruise&key=MYKEY',{headers: {'Access-Control-Allow-Origin': '*'}})
.then(response => this.setState({restaurantsFetchedFromGoogle:response.data}));

但我仍然在我的控制台上收到No 'Access-Control-Allow-Origin' header is present on the requested resource。网址正常工作,因为它在使用Postman时获取结果。我做错了什么?

1 个答案:

答案 0 :(得分:0)

npm install cors --save解决,删除{headers: {'Access-Control-Allow-Origin': '*'}}并重新运行localserver