首页 > 解决方案 > 在 IE11 中获取“标题未定义”

问题描述

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

在此处输入图像描述

它指向这行代码:

import {EventEmitter} from 'events';

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

class ApiService extends EventEmitter {

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

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

现在我得到:

对象不支持属性或方法“值”

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

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

导出 { 默认数据表 };

标签: javascriptreactjsfetchinternet-explorer-11

解决方案


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

参考:

标头

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

  1. 获取标题 polyfill

  2. window.fetch polyfill


推荐阅读