获取未在Safari中定义(ReferenceError:找不到变量:fetch) [英] fetch not defined in Safari (ReferenceError: Can't find variable: fetch)

查看:448
本文介绍了获取未在Safari中定义(ReferenceError:找不到变量:fetch)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于某种原因 fetch https://fetch.spec.whatwg。在Safari(版本9.0.3)中没有定义org / ,有谁知道为什么?它似乎是标准,在Chrome和Firefox中运行良好。似乎找不到其他人有同样的问题

For some reason fetch (https://fetch.spec.whatwg.org/) is not defined in Safari (Version 9.0.3), does anyone know why? It seems to be the standard and works fine in Chrome and Firefox. Can't seem to find anyone else having the same issue

我正在使用与redux的反应,这里是一些示例代码:

I am using react with redux and here is some example code:

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用于不支持的浏览器。

You can use https://github.com/github/fetch polyfill for unsupported browsers.

npm install whatwg-fetch --save; 

(根据评论)

add

import 'whatwg-fetch'; 

- oliviergg

in each file before using fetch – oliviergg

这篇关于获取未在Safari中定义(ReferenceError:找不到变量:fetch)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆