无法在IE 11中完全在React中获取polyfill [英] Fetch polyfill in React not completely working in IE 11

查看:61
本文介绍了无法在IE 11中完全在React中获取polyfill的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此访存在Chrome中工作正常:

This fetch works fine in Chrome:

fetch( this.props.url, {credentials:'same-origin'})
    .then( (data) => data.json() )
    .then( (data) => {
      if( data.length > 0) {
          // do some stuff
      } else {
          console.log('No data Richard of the Beard of the Lewis.');
      }
}); 

我正在使用 isomorphic-fetch ,并且用promise-polyfill来实现我的诺言.我正在使用webpack和babel来编译js.

I am using isomorphic-fetch, and I am polyfilling my promise with promise-polyfill. I'm using webpack and babel to compile the js.

当我在IE11中执行此代码时,将执行对数据的初始获取,并且我的响应中确实包含了所请求的数据,但随后我的任何内容似乎都没有执行(我在几个不同的地方应用了console.logs来查看如果在提取完成后他们还是抽搐了……就不行了).我没有控制台错误,所以我认为IE11对已编译的js语法足够满意.

When I execute this code in IE11, the initial fetch of data executes and my response does contain the requested data, but nothing within my then appears to execute at all (I've applied console.logs in several different places to see if they were twitching at all after the fetch completed...no go). I have no console errors, so I assume IE11 is happy enough with the compiled js' syntax.

有人可以帮我试试吗?我是否需要以更详细的方式重新编写fetch语句,以便IE11能够完全执行它?在这一点上,任何事情都是有帮助的!感谢您的输入.

Does anybody have a clue for me to try? Do I need to re-write my fetch statement in some more verbose way so that IE11 will execute it completely? Anything is helpful at this point! Thanks for any input.

推荐答案

我们需要添加一个polyfill以便在IE中进行抓取,请参考适合您的

We need to add a polyfill for fetch in IE, please refer to this polyfill that works for you https://github.com/github/fetch

这篇关于无法在IE 11中完全在React中获取polyfill的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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