我正在用react和redux構建一個項目,但我無法連接到我的API
。 我有這個,連接API - redux
componentDidMount() {
const {dispatch} = this.props;
dispatch(fetchByQuerystring());
}
和fetchByQuerystring
是:
export function fetchByQuerystring() {
return function(dispatch) {
return fetch(`http://my_domain.dev/api`)
.then(response => response.json())
.then(json => dispatch(receiveByQuerystring(json)));
}
}
當我運行它,我得到這個錯誤:
Fetch API cannot load http://my-domain.dev/api . No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' http://localhost:3000 ' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
我怎樣才能解決這個問題?