如何为String.repeat方法为ie11添加多填充?我没有在我的代码中直接使用它,它可能是一些导入的库。
在IE控制台中,我得到了以下错误:Object doesn't support property or method 'repeat'
我还得到了'AbortController' is undefined,我也没有使用我的代码,可能是外部库。
我使用应用程序,并在index.js中导入:
import 'react-app-polyfill/ie9';
import 'react-app-polyfill/ie11';
import 'react-app-polyfill/stable';我尝试将对象/字符串/重复#填充添加到我的index.js中,但它什么也没做。
还有其他人有类似的问题吗?
发布于 2020-05-10 12:48:10
要为String.repeat添加一个IE11填充,我建议使用core-js库来填充缺少的特性。
通过运行以下命令安装core-js:
npm install --save core-js@3.6.5在src/index.js内部,在最上面导入适当的填充:
import 'react-app-polyfill/ie11';
import 'react-app-polyfill/stable';
import 'core-js/features/string/repeat';
import React from 'react';
// ...对于AbortController,通过运行以下命令来安装它:
npm install --save abortcontroller-polyfill编辑您的src/index.js文件以导入它:
import 'react-app-polyfill/ie11';
import 'react-app-polyfill/stable';
import 'core-js/features/string/repeat';
import 'abortcontroller-polyfill';
import React from 'react';
// ...promise-polyfill/src/polyfill和unfetch/polyfill for AbortController,因为IE11的create-react-apps填充已经与Promise和fetch create-react-apps 一起出现了
create-react-app IE11填充,我建议您查看以下答案:
发布于 2020-05-10 11:53:58
这是IE的ES6不兼容问题。
添加以下npm填充
promise-polyfill
unfetch
abortcontroller-polyfill然后像进口一样
import Promise from "promise-polyfill";
import fetch from 'unfetch';
import 'abortcontroller-polyfill';对于Abortcontroller
对于Object.repeat,首先将MDN的填充代码复制并粘贴到JS文件中。那个可以。
编辑 For React -应该如下所示(您可以在index.js__中这样做)
// import polyfills
import 'react-app-polyfill/stable';
import 'react-app-polyfill/ie11';
import Promise from "promise-polyfill";
import fetch from 'unfetch';
import 'abortcontroller-polyfill';https://stackoverflow.com/questions/60453044
复制相似问题