vue 部署项目的时候报错 token.type.endsWith is not a function

新手上路,请多包涵

vue 部署项目的时候报错 Syntax Error: TypeError: token.type.endsWith is not a function 有没有小伙伴遇到过类似问题 请指教!!

阅读 8.2k
3 个回答
两个解决方案,自己的工程用的第二个
  1. 降低 babel-eslint 的版本
  2. babel 升级到 v7 参考文档

endsWith 方法不支持, 解决方案有两种

  1. 重写 string 类型的 endsWith 方法

    if (!String.prototype.endsWith) {
      //判断String这个对象原型是否有endsWith方法,没有的话,就用加上这个方法
      Object.defineProperty(String.prototype, 'endsWith', {
       enumerable: false,
       configurable: false,
       writable: false,
       value: function (searchString, position) {
           position = position || this.length;
           position = position - searchString.length;
           var lastIndex = this.lastIndexOf(searchString);
           return lastIndex !== -1 && lastIndex === position;
       }
      });
    }
  2. 引入 https://cdn.bootcss.com/babel...

帮忙支持我的工具

https://gitee.com/sanri/sanri...

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题