簡體   English   中英

使用 react polyfills 但出現錯誤 Object 不支持 IE11 中的屬性或方法“重復”

[英]Using react polyfills but getting error Object doesn't support property or method 'repeat' in IE11

我正在使用 react polyfills,並且該站點在 IE11 中工作,除非使用

   changeHeight() {
     let height = 0;
       for (let child of this.Element.current.children) {
       height = Math.max(height, child.clientHeight);
       }
    this.Element.current.style.height = `${height}px`;
    }

IE 中的錯誤是Object 不支持屬性或方法“重復”

我在 package.json 中定義了瀏覽器並導入了以下內容

  • 導入'react-app-polyfill/ie11';
  • 導入'react-app-polyfill/stable'

但頁面不會呈現。

我也收到錯誤

SCRIPT5022:拋出異常但未捕獲

main.chunk.js (6068,465)

IE 11 不支持新的 ECMAScript 2015 的repeat()方法。 您可以添加以下polyfill來修復它:

if (!String.prototype.repeat) {
  String.prototype.repeat = function(count) {
    'use strict';
    if (this == null)
      throw new TypeError('can\'t convert ' + this + ' to object');

    var str = '' + this;
    // To convert string to integer.
    count = +count;
    // Check NaN
    if (count != count)
      count = 0;

    if (count < 0)
      throw new RangeError('repeat count must be non-negative');

    if (count == Infinity)
      throw new RangeError('repeat count must be less than infinity');

    count = Math.floor(count);
    if (str.length == 0 || count == 0)
      return '';

    // Ensuring count is a 31-bit integer allows us to heavily optimize the
    // main part. But anyway, most current (August 2014) browsers can't handle
    // strings 1 << 28 chars or longer, so:
    if (str.length * count >= 1 << 28)
      throw new RangeError('repeat count must not overflow maximum string size');

    var maxCount = str.length * count;
    count = Math.floor(Math.log(count) / Math.log(2));
    while (count) {
       str += str;
       count--;
    }
    str += str.substring(0, maxCount - str.length);
    return str;
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM