首页 > 解决方案 > 接收到请求的资源上不存在“Access-Control-Allow-Origin”标头,并带有 axios get 请求

问题描述

我正在使用以下请求:

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在我的控制台上收到。该 url 工作正常,因为它在使用 Postman 时获取结果。我究竟做错了什么?

标签: corsaxios

解决方案


解决方法npm install cors --save,移除{headers: {'Access-Control-Allow-Origin': '*'}}并重新运行本地服务器


推荐阅读