Javascript Safari中未定义fetch(ReferenceError:Can';t find变量:fetch)

Javascript Safari中未定义fetch(ReferenceError:Can';t find变量:fetch),javascript,safari,fetch-api,Javascript,Safari,Fetch Api,出于某种原因,Safari(9.0.3版)中没有定义获取(),有人知道为什么吗?这似乎是标准,在Chrome和Firefox中运行良好。似乎找不到其他人有同样的问题 我正在使用react with redux,下面是一些示例代码: export function fetchData (url) { return dispatch => { dispatch(loading()) fetch(url, { method: 'GET' }) .t

出于某种原因,Safari(9.0.3版)中没有定义
获取
(),有人知道为什么吗?这似乎是标准,在Chrome和Firefox中运行良好。似乎找不到其他人有同样的问题

我正在使用react with redux,下面是一些示例代码:

export function fetchData (url) {
  return dispatch => {
    dispatch(loading())
    fetch(url, {
      method: 'GET'
    })
    .then(response => {
      response.json()
      .then(data => {
        dispatch(success(data))
      })
    })
  }
}
您可以对不受支持的浏览器使用polyfill

npm install whatwg-fetch --save; 
编辑:(根据评论)


在使用fetch之前的每个文件中–oliviergg

使用
whatwg fetch
polyfill。 如果您使用
webpack
,您可以将其添加到入口点

entry: {
  app: ['whatwg-fetch', 'your-index.js']
}

fetch
不受Safari支持。两年前,Safari仍然不支持fetch。。。这个浏览器太可怜了!谢谢,我应该知道这一点。我正在使用它(es6 promise polyfill也一样),但在iOS上查看它时,我总是会遇到完全相同的错误。(没有可编辑的评论。)Stock Android也有同样的问题。@nickvda尝试添加
import'whatwg fetch'在使用fetch之前
entry: {
  app: ['whatwg-fetch', 'your-index.js']
}