在项目中任意一处引入mui.min.js报如下错误:
Uncaught TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them
at Function.d.extend (mui.min.js?9ccf:7)
at eval (mui.min.js?9ccf:7)
at eval (mui.min.js?9ccf:7)
at Object../src/lib/dist/js/mui.min.js (app.js:2074)
at __webpack_require__ (app.js:679)
at fn (app.js:89)
at eval (selector.js?type=script&index=0!./src/components/photoList.vue:1)
at Object../node_modules/babel-loader/lib/index.js!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/components/photoList.vue (app.js:899)
at __webpack_require__ (app.js:679)
at fn (app.js:89)
原因:babel在将js文件转码为ES5时,默认使用严格模式,而在严格模式下,为了安全起见是不能用caller,callee,arguments等属性的。
解决方式如下:
分别在.babelrc文件和.eslintignore文件添加如下规则:
【.babelrc文件,在“plugins”:[]后添加】
"ignore": [
"src/lib/dist/js/mui.min.js"
]
【.eslintignore文件添加】
src/lib/dist/js/mui.min.js
此处的路径指的是mui.min.js文件所在的相对路径,如果路径写错还是会报错,所以得注意这个路径的正确与否。如果不知道怎么确定这个路径,可以这样做:
在mui.min.js文件上点击右键,选择copy relative path,然后直接把这个路径复制到两个文件中去,之后就一切正常了。如图: