ES6`fetch是未定义的 [英] ES6 `fetch is undefined`

查看:1737
本文介绍了ES6`fetch是未定义的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ES6和Babel建立一个网站。



在脚本文件中,我需要对服务器上的服务进行ajax调用。因为这样做:

  fetch('url')。then(
response => response.json()
).then(
supervisoryItems => doSomething(supervisoryItems)

在Google Chrome中,这个功能很好,但在Firefox或IE上无效(我收到错误 fetch is undefined ) 。
在Google上搜索我发现这应该解决它:

 'es6-promise'的导入承诺
promise.polyfill()

遗憾的是,它没有改变任何东西,我有同样的问题。任何帮助?

解决方案

您需要将'isomorphic-fetch'模块添加到'package.json',然后导入。

  npm install --save isomorphic-fetch es6-promise 

然后在你的代码中

  importisomorphic-fetch

请参阅 https://www.npmjs.com/package/isomorphic-fetch


I'm building a site with ES6 and Babel.

In a script file, I need to make an ajax call to a service on server. For that I'm doing like this:

fetch('url').then(
    response => response.json()
).then(
    supervisoryItems => doSomething(supervisoryItems)
)

In Google Chrome this works just fine, but it does not work on Firefox or IE (I'm getting the error fetch is undefined). Searching on Google I found this should fix it:

import promise from 'es6-promise'
promise.polyfill()

Sadly it does not change anything, I have the same issue. Any help?

解决方案

You need to add the 'isomorphic-fetch' module to your 'package.json' and then import this.

npm install --save isomorphic-fetch es6-promise

Then in your code

import "isomorphic-fetch"

See https://www.npmjs.com/package/isomorphic-fetch

这篇关于ES6`fetch是未定义的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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