簡體   English   中英

邊緣和 ie11 上的 Nextjs 'endsWith' polyfill 問題

[英]Nextjs 'endsWith' polyfill problem on edge and ie11

由於Object doesn't support property or method 'endsWith'錯誤,我的站點中斷並無法運行。 我試過用import 'core-js/features/string/ends-with'

if (!String.prototype.endsWith) {
  String.prototype.endsWith = function (search, this_len) {
    if (this_len === undefined || this_len > this.length) {
      this_len = this.length
    }
    return this.substring(this_len - search.length, this_len) === search
  }
}

我已經在我的自定義_app文件中做到了這一點,但它在 edge 和 ie11 中仍然失敗。 我錯過了什么?

編輯:從https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith#Browser_compatibility endsWith來看,Edge 應該支持

在此處輸入圖片說明

嘗試將其添加到您的代碼中。

String.prototype.endsWith = function(pattern) {
  var d = this.length - pattern.length;
  return d >= 0 && this.lastIndexOf(pattern) === d;
};

暫無
暫無

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

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