我已经看到这个问题被多个人问到,但没有一个答案对我有用。我正在尝试使用react / axios对Google Maps api进行API调用。这是我的要求:componentDidMount() { axios({ method : 'get', url : `http://maps.googleapis.com/maps/api/js?key=${key}/`, headers: { "Access-Control-Allow-Origin": '*' "Access-Control-Allow-Methods": 'GET', }, }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); });}这是错误消息:XMLHttpRequest cannot load http://maps.googleapis.com/maps/api/js?key=xxxxxxxxx/. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.我已经阅读了con CORS文章,其他所有人都指向 https://www.html5rocks.com/en/tutorials/cors/但我在那里找不到解决问题的答案。
1 回答
- 1 回答
- 0 关注
- 554 浏览
添加回答
举报
0/150
提交
取消