详解Vue取消eslint语法限制


Posted in Javascript onAugust 04, 2018

由于vue对语法的限制过于严格,以至于在我第一次编译运行的时候一直编译失败,当然也包括一些警告:

➜ my-project npm run dev 
 
> bblee-app@1.0.0 dev /Users/bianlifeng/my-project
> webpack-dev-server --inline --progress --config build/webpack.dev.conf.js
 
 95% emitting                                      
 
 WARNING Compiled with 1 warnings                                                               5:00:12 PM
 
 
 ✘ http://eslint.org/docs/rules/indent            Expected indentation of 0 spaces but found 2  
 src/components/Message.vue:46:1
  export default {
  ^
 
 ✘ http://eslint.org/docs/rules/indent            Expected indentation of 2 spaces but found 4  
 src/components/Message.vue:47:1
   data() {
  ^
 
 ✘ http://eslint.org/docs/rules/space-before-function-paren Missing space before function parentheses   
 src/components/Message.vue:47:9
   data() {
      ^
 
 ✘ http://eslint.org/docs/rules/indent            Expected indentation of 4 spaces but found 6  
 src/components/Message.vue:48:1
    return {
  ^
 
 ✘ http://eslint.org/docs/rules/indent            Expected indentation of 6 spaces but found 8  
 src/components/Message.vue:49:1
     form: {
  ^
 
 ✘ http://eslint.org/docs/rules/indent            Expected indentation of 8 spaces but found 10 
 src/components/Message.vue:50:1
      name: '',
  ^
 
 ✘ http://eslint.org/docs/rules/indent            Expected indentation of 8 spaces but found 10 
 src/components/Message.vue:51:1
      region: '',
  ^
 
 ✘ http://eslint.org/docs/rules/indent            Expected indentation of 8 spaces but found 10 
 src/components/Message.vue:52:1
      date1: '',
  ^
 
 ✘ http://eslint.org/docs/rules/indent            Expected indentation of 8 spaces but found 10 
 src/components/Message.vue:53:1
      date2: '',
  ^
 
 ✘ http://eslint.org/docs/rules/indent            Expected indentation of 8 spaces but found 10 
 src/components/Message.vue:54:1
      delivery: false,
  ^
 
 ✘ http://eslint.org/docs/rules/indent            Expected indentation of 8 spaces but found 10 
 src/components/Message.vue:55:1
      type: [],
  ^
 
 ✘ http://eslint.org/docs/rules/indent            Expected indentation of 8 spaces but found 10 
 src/components/Message.vue:56:1
      resource: '',
  ^
 
 ✘ http://eslint.org/docs/rules/indent            Expected indentation of 8 spaces but found 10 
 src/components/Message.vue:57:1
      desc: ''
  ^
 
 ✘ http://eslint.org/docs/rules/indent            Expected indentation of 6 spaces but found 8  
 src/components/Message.vue:58:1
     }
  ^
 
 ✘ http://eslint.org/docs/rules/indent            Expected indentation of 4 spaces but found 6  
 src/components/Message.vue:59:1
    }
  ^
 
 ✘ http://eslint.org/docs/rules/indent            Expected indentation of 2 spaces but found 4  
 src/components/Message.vue:60:1
   },
  ^
 
 ✘ http://eslint.org/docs/rules/indent            Expected indentation of 2 spaces but found 4  
 src/components/Message.vue:61:1
   methods: {
  ^
 
 ✘ http://eslint.org/docs/rules/indent            Expected indentation of 4 spaces but found 6  
 src/components/Message.vue:62:1
    onSubmit() {
  ^
 
 ✘ http://eslint.org/docs/rules/space-before-function-paren Missing space before function parentheses   
 src/components/Message.vue:62:15
    onSubmit() {
         ^
 
 ✘ http://eslint.org/docs/rules/indent            Expected indentation of 6 spaces but found 8  
 src/components/Message.vue:63:1
     console.log('submit!');
  ^
 
 ✘ http://eslint.org/docs/rules/indent            Expected indentation of 4 spaces but found 6  
 src/components/Message.vue:64:1
    }
  ^
 
 ✘ http://eslint.org/docs/rules/indent            Expected indentation of 2 spaces but found 4  
 src/components/Message.vue:65:1
   }
  ^
 
 ✘ http://eslint.org/docs/rules/indent            Expected indentation of 0 spaces but found 2  
 src/components/Message.vue:66:1
  }
  ^
 
 
✘ 23 problems (23 errors, 0 warnings)
 
 
Errors:
 21 http://eslint.org/docs/rules/indent
  2 http://eslint.org/docs/rules/space-before-function-paren
 
You may use special comments to disable some warnings.
Use // eslint-disable-next-line to ignore the next line.
Use /* eslint-disable */ to ignore all warnings in a file.

当然,这里的警告我是知道怎么回事,但是这个错误我就很不明白了,原来eslint是一个语法检查工具,但是限制很严格,在我的vue文件里面很多空格都会导致红线(红线可以关闭提示),虽然可以关闭,但是在编译的时候老是会跳出来,所以能关闭是最好的了。

关闭方法:

在build/webpack.base.conf.js文件中,注释或者删除掉:module->rules中有关eslint的规则

module: {
 rules: [
  //...(config.dev.useEslint ? [createLintingRule()] : []), // 注释或者删除
  {
   test: /\.vue$/,
   loader: 'vue-loader',
   options: vueLoaderConfig
  },
  ...
  }
 ]
}

然后重新运行一下npm run dev或者构建命令 npm run build就可以啦。

Javascript 相关文章推荐
javascript+dom树型菜单类,希望朋友们一起进步
May 03 Javascript
JS实现3D图片旋转展示效果代码
Sep 22 Javascript
JS常用函数和常用技巧小结
Oct 15 Javascript
Angularjs的Controller间通信机制实例分析
Nov 07 Javascript
浅谈javascript alert和confirm的美化
Dec 15 Javascript
EasyUI为Numberbox添加blur事件的方法
Mar 05 Javascript
详解Node.js串行化流程控制
May 04 Javascript
Javascript之图片的延迟加载的实例详解
Jul 24 Javascript
JavaScript使用Ajax上传文件的示例代码
Aug 10 Javascript
自制简易打赏功能的实例
Sep 02 Javascript
vue移动端模态框(可传参)的实现
Nov 20 Javascript
JS使用正则表达式实现常用的表单验证功能分析
Apr 30 Javascript
JavaScript原型对象、构造函数和实例对象功能与用法详解
Aug 04 #Javascript
JavaScript中变量、指针和引用功能与操作示例
Aug 04 #Javascript
webpack4.x开发环境配置详解
Aug 04 #Javascript
微信小程序实现收藏与取消收藏切换图片功能
Aug 03 #Javascript
解决mpvue + vuex 开发微信小程序vuex辅助函数mapState、mapGetters不可用问题
Aug 03 #Javascript
mpvue跳转页面及注意事项
Aug 03 #Javascript
JavaScript高级函数应用之分时函数实例分析
Aug 03 #Javascript
You might like
PHP 获取MySQL数据库里所有表的实现代码
2011/07/13 PHP
php中经典方法实现判断多维数组是否为空
2011/10/23 PHP
浅析Yii中使用RBAC的完全指南(用户角色权限控制)
2013/06/20 PHP
php使用GD2绘制几何图形示例
2017/02/15 PHP
PHP chr()函数讲解
2019/02/11 PHP
Thinkphp5.0框架视图view的循环标签用法示例
2019/10/12 PHP
javascript获取当前日期时间及其它操作函数
2011/01/11 Javascript
JavaScript高级程序设计 阅读笔记(十七) js事件
2012/08/14 Javascript
JS实现关键字搜索时的相关下拉字段效果
2014/08/05 Javascript
javascript实现的平方米、亩、公顷单位换算小程序
2014/08/11 Javascript
为什么Node.js会这么火呢?Node.js流行的原因
2014/12/01 Javascript
AngularJS 实现JavaScript 动画效果详解
2016/09/08 Javascript
JS 调用微信扫一扫功能
2016/12/22 Javascript
基于bootstrap的选择框插件icheck
2016/12/23 Javascript
微信小程序开发(二)图片上传+服务端接收详解
2017/01/11 Javascript
浅谈PDF.js使用心得
2018/06/07 Javascript
[49:35]LGD vs OG 2018国际邀请赛淘汰赛BO3 第二场 8.25
2018/08/29 DOTA
[04:32]玩具屠夫中文语音节选
2020/08/23 DOTA
Python的Flask框架中配置多个子域名的方法讲解
2016/06/07 Python
python 获取list特定元素下标的实例讲解
2018/04/09 Python
python logging日志模块以及多进程日志详解
2018/04/18 Python
django mysql数据库及图片上传接口详解
2019/07/18 Python
VSCode中自动为Python文件添加头部注释
2019/11/14 Python
python3.8与pyinstaller冲突问题的快速解决方法
2020/01/16 Python
python实现简单飞行棋
2020/02/06 Python
Python如何使用正则表达式爬取京东商品信息
2020/06/01 Python
keras 读取多标签图像数据方式
2020/06/12 Python
win10安装python3.6的常见问题
2020/07/01 Python
Python自动巡检H3C交换机实现过程解析
2020/08/14 Python
选购国际女性时装设计师品牌:IFCHIC(支持中文)
2018/04/12 全球购物
司机的工作范围及职责
2013/11/13 职场文书
网站美工岗位职责
2014/04/02 职场文书
电气工程师岗位职责
2015/02/12 职场文书
培训通知书模板
2015/04/17 职场文书
爱护环境卫生倡议书
2015/04/29 职场文书
2015年暑期社会实践总结
2015/07/13 职场文书