zoukankan      html  css  js  c++  java
  • [vue问题解决]vue-cli项目引用mui.js报错Uncaught TypeError: 'caller', 'callee', and 'arguments' properties may not be...

    引用mui.js

    报错信息:

    Uncaught TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them
    

    方案一

    原因:babel在将js文件转码为ES5时,默认使用严格模式,而在严格模式下,为了安全起见是不能用caller,callee,arguments等属性的。

    解决: 修改bablerc文件的配置,让项目忽略mui.js的转码,完美解决我的问题

    "ignore": [
        "./src/assets/lib/mui/js/mui.js"
      ]
    

    此外,如果设置了语法检查,也会各种检查第三方js的语法错误,从而报错。通过修改eslintignor文件,将对应目录下的js忽略即可

    方案二

    移除严格模式:

    npm i babel-plugin-transform-remove-strict-mode -D
    

    .babelrc添加transform-remove-strict-mode

    "plugins": [
       "transform-vue-jsx",
       "transform-runtime",  
       "transform-remove-strict-mode"
     ]
    

    以上解决方案用到我的vue-cli项目中会报错:"export 'default' (imported as 'mui') was not found in '../../assets/lib/mui/js/mui.js'

    但同一个例子没用vue-cli,用方案二却完美解决。

    补充

    也有看到博主说添加 transform-remove-strict-mode 并将 transform-runtime 移除。个人觉得用 ignore 只是忽略了指定第三方js的转码,如果移除了 transform-runtime,这就相当于移除了一个项目的代码转换插件,嗯,做的很绝啊。

    关于babel将高级语法转为ES5,推荐看一下:Babel之babel-polyfill、babel-runtime、transform-runtime详解

  • 相关阅读:
    js对象数组中的某属性值 拼接成字符串
    mongodb 简单的增删改查
    celery简单使用
    Redis简单操作
    三大认证源码分析
    认证、权限、频率、自定义签发token-多方式登录
    jwt认证
    视图家族
    day75作业
    day74作业
  • 原文地址:https://www.cnblogs.com/L-xmin/p/12494688.html
Copyright © 2011-2022 走看看