fetch未在Safari中定义(ReferenceError:找不到变量:获取)
由于某些原因,fetch
(https://fetch.spec.whatwg.org/)未在Safari(版本9.0.3)中定义,有谁知道为什么?它似乎是标准,并在Chrome和Firefox中正常运行。似乎无法找到任何人有同样的问题fetch未在Safari中定义(ReferenceError:找不到变量:获取)
我使用与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填充工具不支持的浏览器。
npm install whatwg-fetch --save;
编辑:(每评论)
在每个文件中使用取前加
import 'whatwg-fetch';
- oliviergg
谢谢,应该知道。 – zlwaterfield
我使用的是(es6-promise polyfill),但在iOS上查看时,我仍然得到了完全相同的错误。 – Nickvda
(无编辑可用于评论..):股票Android有同样的问题。 – Nickvda
使用whatwg-fetch
填充工具。 如果使用webpack
,你可以只将它添加到入口点
entry: {
app: ['whatwg-fetch', 'your-index.js']
}
http://caniuse.com/#search=fetch'fetch'没有Safari支援。 –