【发布时间】:2016-11-21 06:42:07
【问题描述】:
我正在使用 react 和 redux 构建一个项目,但我无法连接到我的 API。
我有这个,
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 无法加载 http://my-domain.dev/api。不 'Access-Control-Allow-Origin' 标头出现在请求的 资源。因此不允许使用原点“http://localhost:3000” 使用权。如果不透明的响应满足您的需求,请设置请求的 模式为“no-cors”以获取禁用 CORS 的资源。
我该如何解决这个问题?
【问题讨论】:
标签: php laravel-5 fetch react-redux