一直在寻找解决这个问题的方法:
Fetch API无法加载https://api.wunderground.com/api/ ****** / conditions / q / toronto . 'Access-Control-Allow-Origin'标头具有值_137204_ ' that is not equal to the supplied origin. Origin ' http://localhost:3000 ' is therefore not allowed access. Have the server send the header with a valid value, or, if an opaque response serves your needs, set the request' s模式到'no-cors'以获取禁用CORS的资源 .
const apiKey = '******'
const apiUrl = 'https://api.wunderground.com/api/' + apiKey + '/conditions/q/'
var WeatherApi = {
get: function(query) {
return fetch(apiUrl + query).then(function(response) {
return response.json();
});
}
};
handleClick: function() {
WeatherApi.get(this.state.text).then(function(data) {
console.log(data);
}.bind(this));
},
那么如何让服务器发送带有效值的标头?