因为某些原因fetch
(https://fetch.spec.whatwg.org/ https://fetch.spec.whatwg.org/)在 Safari(版本 9.0.3)中没有定义,有谁知道为什么?它似乎是标准并且在 Chrome 和 Firefox 中运行良好。似乎找不到其他人有同样的问题
我正在使用 React 和 redux,这里是一些示例代码:
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 https://github.com/github/fetch针对不支持的浏览器的polyfill。
npm install whatwg-fetch --save;
编辑:(根据评论)
add
import 'whatwg-fetch';
在使用 fetch 之前在每个文件中 – oliviergg
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)