详解Vue取消eslint语法限制
由于vue对语法的限制过于严格,以至于在我第一次编译运行的时候一直编译失败,当然也包括一些警告:
➜my-projectnpmrundev >bblee-app@1.0.0dev/Users/bianlifeng/my-project >webpack-dev-server--inline--progress--configbuild/webpack.dev.conf.js 95%emitting WARNINGCompiledwith1warnings5:00:12PM ✘http://eslint.org/docs/rules/indentExpectedindentationof0spacesbutfound2 src/components/Message.vue:46:1 exportdefault{ ^ ✘http://eslint.org/docs/rules/indentExpectedindentationof2spacesbutfound4 src/components/Message.vue:47:1 data(){ ^ ✘http://eslint.org/docs/rules/space-before-function-parenMissingspacebeforefunctionparentheses src/components/Message.vue:47:9 data(){ ^ ✘http://eslint.org/docs/rules/indentExpectedindentationof4spacesbutfound6 src/components/Message.vue:48:1 return{ ^ ✘http://eslint.org/docs/rules/indentExpectedindentationof6spacesbutfound8 src/components/Message.vue:49:1 form:{ ^ ✘http://eslint.org/docs/rules/indentExpectedindentationof8spacesbutfound10 src/components/Message.vue:50:1 name:'', ^ ✘http://eslint.org/docs/rules/indentExpectedindentationof8spacesbutfound10 src/components/Message.vue:51:1 region:'', ^ ✘http://eslint.org/docs/rules/indentExpectedindentationof8spacesbutfound10 src/components/Message.vue:52:1 date1:'', ^ ✘http://eslint.org/docs/rules/indentExpectedindentationof8spacesbutfound10 src/components/Message.vue:53:1 date2:'', ^ ✘http://eslint.org/docs/rules/indentExpectedindentationof8spacesbutfound10 src/components/Message.vue:54:1 delivery:false, ^ ✘http://eslint.org/docs/rules/indentExpectedindentationof8spacesbutfound10 src/components/Message.vue:55:1 type:[], ^ ✘http://eslint.org/docs/rules/indentExpectedindentationof8spacesbutfound10 src/components/Message.vue:56:1 resource:'', ^ ✘http://eslint.org/docs/rules/indentExpectedindentationof8spacesbutfound10 src/components/Message.vue:57:1 desc:'' ^ ✘http://eslint.org/docs/rules/indentExpectedindentationof6spacesbutfound8 src/components/Message.vue:58:1 } ^ ✘http://eslint.org/docs/rules/indentExpectedindentationof4spacesbutfound6 src/components/Message.vue:59:1 } ^ ✘http://eslint.org/docs/rules/indentExpectedindentationof2spacesbutfound4 src/components/Message.vue:60:1 }, ^ ✘http://eslint.org/docs/rules/indentExpectedindentationof2spacesbutfound4 src/components/Message.vue:61:1 methods:{ ^ ✘http://eslint.org/docs/rules/indentExpectedindentationof4spacesbutfound6 src/components/Message.vue:62:1 onSubmit(){ ^ ✘http://eslint.org/docs/rules/space-before-function-parenMissingspacebeforefunctionparentheses src/components/Message.vue:62:15 onSubmit(){ ^ ✘http://eslint.org/docs/rules/indentExpectedindentationof6spacesbutfound8 src/components/Message.vue:63:1 console.log('submit!'); ^ ✘http://eslint.org/docs/rules/indentExpectedindentationof4spacesbutfound6 src/components/Message.vue:64:1 } ^ ✘http://eslint.org/docs/rules/indentExpectedindentationof2spacesbutfound4 src/components/Message.vue:65:1 } ^ ✘http://eslint.org/docs/rules/indentExpectedindentationof0spacesbutfound2 src/components/Message.vue:66:1 } ^ ✘23problems(23errors,0warnings) Errors: 21http://eslint.org/docs/rules/indent 2http://eslint.org/docs/rules/space-before-function-paren Youmayusespecialcommentstodisablesomewarnings. Use//eslint-disable-next-linetoignorethenextline. Use/*eslint-disable*/toignoreallwarningsinafile.
当然,这里的警告我是知道怎么回事,但是这个错误我就很不明白了,原来eslint是一个语法检查工具,但是限制很严格,在我的vue文件里面很多空格都会导致红线(红线可以关闭提示),虽然可以关闭,但是在编译的时候老是会跳出来,所以能关闭是最好的了。
关闭方法:
在build/webpack.base.conf.js文件中,注释或者删除掉:module->rules中有关eslint的规则
module:{ rules:[ //...(config.dev.useEslint?[createLintingRule()]:[]),//注释或者删除 { test:/\.vue$/, loader:'vue-loader', options:vueLoaderConfig }, ... } ] }
然后重新运行一下npmrundev或者构建命令npmrunbuild就可以啦。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。