由于某些原因fetch
(https://fetch.spec.whatwg.org/)在Safari(版本9.0.3)中未定义,有人知道为什么吗?它似乎是标准的,并且可以在Chrome和Firefox中正常运行。似乎找不到其他遇到相同问题的人
我正在与redux一起使用react,这是一些示例代码:
export function fetchData (url) {
return dispatch => {
dispatch(loading())
fetch(url, {
method: 'GET'
})
.then(response => {
response.json()
.then(data => {
dispatch(success(data))
})
})
}
}
您可以对不支持的浏览器使用https://github.com/github/fetch polyfill。
npm install whatwg-fetch --save;
编辑:(根据评论)
添加
import 'whatwg-fetch';
在使用提取之前在每个文件中– oliviergg
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句