2

我们正在制作一个 V2 Docusaurus 网站:https ://www.10studio.tech 。

我们刚刚意识到它在 IE 中不能很好地工作,例如 IE11。错误信息是:Object doesn't support property or method 'assign'

在此处输入图像描述

有一些软件包可以提供 IE 兼容性,例如core-js,但我们不知道如何正确地将其添加到 Docusaurus v2。

有谁知道如何修改这个?

4

1 回答 1

1

错误消息告诉您该对象没有assign function. assign您正在function谈论的浏览器显然不支持它,因此您需要对其进行填充。一个很好的例子是:

if (!Object.assign) {
  Object.defineProperty(Object, 'assign', {
    enumerable: false,
    configurable: true,
    writable: true,
    value: function(target) {
      'use strict';
      if (target === undefined || target === null) {
        throw new TypeError('Cannot convert first argument to object');
      }

      var to = Object(target);
      for (var i = 1; i < arguments.length; i++) {
        var nextSource = arguments[i];
        if (nextSource === undefined || nextSource === null) {
          continue;
        }
        nextSource = Object(nextSource);

        var keysArray = Object.keys(Object(nextSource));
        for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) {
          var nextKey = keysArray[nextIndex];
          var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
          if (desc !== undefined && desc.enumerable) {
            to[nextKey] = nextSource[nextKey];
          }
        }
      }
      return to;
    }
  });
}

可以在这里找到:https ://gist.github.com/spiralx/68cf40d7010d829340cb

但是,即使这可以解决您抱怨的问题,也很可能还会出现其他问题。你可能还需要 polyfill 一些其他的东西,你可能想看看BabelJS以实现这一点。

于 2019-09-14T16:25:14.080 回答