Skip to content
On this page

react项目兼容ie浏览器

使用create-react-app生成的项目

  1. 安装react-app-polyfillcore-js
shell
npm install react-app-polyfill core-js
  1. index.js中引入
typescript
import 'core-js/es'
import 'react-app-polyfill/ie9'
import 'react-app-polyfill/stable'
  1. 修改package.json的配置
json
"browserslist": {
    "production": [
        ">0.2%",
        "not dead",
        "not op_mini all",
        "ie > 9"
    ],
    "development": [
        "last 1 chrome version",
        "last 1 firefox version",
        "last 1 safari version",
        "ie > 9"
    ]
}
  1. 如果没有效果删除node_modules文件夹重新下载
  2. 如果还不行,可能是没有设置ie文档模式的原因,在index.html中添加
html
<meta http-equiv="X-UA-Compatible" content="IE=edge" />

不是使用create-react-app创建的项目

无需配置react-app-polyfillpackage.json,其他的同上

更新时间: