React 不兼容 IE,
来自官方文档:
React 支持所有流行的浏览器,包括 Internet Explorer 9 及更高版本,但旧版浏览器(如 IE 9 和 IE 10)需要一些 polyfill。
我们不支持不支持 ES5 方法的旧浏览器,但是
如果使用 polyfill,您可能会发现您的应用确实可以在旧版浏览器中运行
例如 es5-shim 和 es5-sham 都包含在页面中。你在你的
如果您选择走这条路,就拥有自己。
要使您的应用程序在 IE(11 或 9)上运行,您必须安装 React-app-polyfill:
https://www.npmjs.com/package/react-app-polyfill
特点:
每个 polyfill 都确保存在以下语言特性:
Promise (for async / await support)
window.fetch (a Promise-based way to make web requests in the browser)
Object.assign (a helper required for Object Spread, i.e. { ...a, ...b })
Symbol (a built-in object used by for...of syntax and friends)
Array.from (a built-in static method used by array spread, i.e. [...arr])
用法
首先,使用 Yarn 或 npm 安装包:
npm install react-app-polyfill
现在,您可以导入要支持的最低版本的入口点。例如,如果您导入 IE9 入口点,这将包括 IE10 和 IE11 支持。
Internet Explorer 9
// This must be the first line in src/index.js
import 'react-app-polyfill/ie9';
// ...
Internet Explorer 11
// This must be the first line in src/index.js
import 'react-app-polyfill/ie11';
// ...
您还可以使用以下文档配置清单以处理不同的浏览器:https://github.com/browserslist/browserslist
例子:
"browserslist": [
">0.2%",
"not dead",
"ie >= 9"
]
更多信息来自official site