在 IE11 中获取 "Headers is undefined"

Getting "Headers is undefined" in IE11

我有一个 React 应用程序,它在除 IE11 之外的所有浏览器中都按预期工作。 在控制台中我可以看到这个错误:

它指向这行代码:

import {EventEmitter} from 'events';

**const headers = new Headers();**
headers.append('Content-Type', 'application/json');
headers.append('Accept', 'application/json');

class ApiService extends EventEmitter {

我已经到达了这些帖子,但我不清楚我应该做什么样的改变!我应该只安装缺少的 pollyfill 还是需要更改代码语法...

'Headers' is undefined in IE11

https://www.codeproject.com/Questions/1275068/Javascript-fetch-not-working-in-internet-explorer

更新

两者都安装后:

window.fetch#https://github.com/github/fetch#read-this-first,

承诺#https://github.com/taylorhakes/promise-polyfill

现在我得到:

Object doesn't support property or method 'values'

我使用了 react-carbon-components 的 DataTable 对象,但似乎也不支持它:

_defineProperty(DataTable, "translationKeys", Object.values(translationKeys));

导出 { DataTable 作为默认值};

Internet Explorer 不支持 Fetch API 的 Headers 接口。

参考:

Headers

要使其与 IE 浏览器一起使用,您需要使用 polyfill。您可以参考以下任何一种 polyfill 可能会帮助您解决问题。

  1. Fetch headers polyfill

  2. window.fetch polyfill