首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对象不支持SPFX web部件中的属性或方法“包括”

对象不支持SPFX web部件中的属性或方法“包括”
EN

Stack Overflow用户
提问于 2020-02-26 16:10:57
回答 1查看 383关注 0票数 2

我有spfx部件1.8.2版本,这是在铬,但不是在ie11中工作。首先,我拥有的对象不支持属性或方法“查找”错误,然后我添加了以下包

代码语言:javascript
复制
import 'polyfill-array-includes';
import "@pnp/polyfill-ie11";
import "core-js/es6/array";
import "es6-map/implement";
import "core-js/modules/es6.array.find";

然后抛出新的错误,因为对象不支持属性或方法‘include’

有什么想法吗?谢谢!

EN

回答 1

Stack Overflow用户

发布于 2020-12-09 13:37:59

参考资料:https://www.cluemediator.com/object-doesnt-support-property-or-method-includes-in-ie

只需将其放入构造函数中,例如:

代码语言:javascript
复制
if (!Array.prototype.includes) {
  Object.defineProperty(Array.prototype, 'includes', {
    value: function (searchElement, fromIndex) {
      if (this == null) {
        throw new TypeError('"this" is null or not defined');
      }

      // 1. Let O be ? ToObject(this value).
      var o = Object(this);

      // 2. Let len be ? ToLength(? Get(O, "length")).
      var len = o.length >>> 0;

      // 3. If len is 0, return false.
      if (len === 0) {
        return false;
      }

      // 4. Let n be ? ToInteger(fromIndex).
      //    (If fromIndex is undefined, this step produces the value 0.)
      var n = fromIndex | 0;

      // 5. If n ≥ 0, then
      //  a. Let k be n.
      // 6. Else n < 0,
      //  a. Let k be len + n.
      //  b. If k < 0, let k be 0.
      var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);

      function sameValueZero(x, y) {
        return x === y || (typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y));
      }

      // 7. Repeat, while k < len
      while (k < len) {
        // a. Let elementK be the result of ? Get(O, ! ToString(k)).
        // b. If SameValueZero(searchElement, elementK) is true, return true.
        if (sameValueZero(o[k], searchElement)) {
          return true;
        }
        // c. Increase k by 1.
        k++;
      }

      // 8. Return false
      return false;
    },
  });
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60418089

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档