私はエラーにNo 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.
Axiosはアクセス制御 - 許可しない-起源
を実行し続ける私はこれが以外に頻繁にウェブ上での質問をし、私はstackoverflowの上ここには参考になっ答えを見ないであることを承知していますJSONPを使用した回避策。
私のコードは
componentDidMount() {
if (navigator.geolocation){
function success(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
axios.get(`https://api.darksky.net/forecast/apikey/`+latitude+`,`+longitude+`?units=auto`)
.then(result => {
this.setState({
daily: result.data.daily.data,
loading: false,
error: null
});
})
.catch(err => {
// Something went wrong. Save the error in state and re-render.
this.setState({
loading: false,
error: err
});
});
};
function error() {
console.log('geolocation error')
};
navigator.geolocation.getCurrentPosition(success.bind(this), error);
}
}
詐欺ターゲット回答の回答がどれも問題を解決しない場合、解決できない可能性があります。 CORSポリシーに従い、XHR(別名jsonp)を要求せずに、またはサーバーから要求を行う必要があります。 –