详解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 相关文章推荐
js removeChild 障眼法 可能出现的错误
Oct 06 Javascript
Javascript调用C#代码
Jan 17 Javascript
JavaScript的parseInt 取整使用
May 09 Javascript
jQuery 过滤方法filter()选择具有特殊属性的元素
Jun 15 Javascript
关注jquery技巧提高jquery技能(前端开发必学)
Nov 02 Javascript
Highcharts 多个Y轴动态刷新数据的实现代码
May 28 Javascript
JS创建Tag标签的方法详解
Jun 09 Javascript
vue.js数据绑定的方法(单向、双向和一次性绑定)
Jul 13 Javascript
微信小程序 同步请求授权的详解
Aug 04 Javascript
jQuery Validate插件ajax方式验证输入值的实例
Dec 21 jQuery
微信小程序开发之左右分栏效果的实例代码
May 20 Javascript
p5.js绘制旋转的正方形
Oct 23 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
Windows和Linux中php代码调试工具Xdebug的安装与配置详解
2014/05/08 PHP
PHP实现的解汉诺塔问题算法示例
2018/08/06 PHP
php实现断点续传大文件示例代码
2020/06/19 PHP
Javascript - HTML的request类
2007/01/09 Javascript
utf-8编码引起js输出中文乱码的解决办法
2010/06/23 Javascript
使用jquery读取html5 localstorage的值的方法
2013/01/04 Javascript
jquery 面包屑导航 具体实现
2013/06/05 Javascript
JQuery中form验证出错信息的查看方法
2013/10/08 Javascript
jQuery表格列宽可拖拽改变且兼容firfox
2014/09/03 Javascript
jQuery实现图片预加载效果
2015/11/27 Javascript
Javascript基于对象三大特性(封装性、继承性、多态性)
2016/01/04 Javascript
EasyUI Pagination 分页的两种做法小结
2016/07/09 Javascript
JS仿hao123导航页面图片轮播效果
2016/09/01 Javascript
JavaScript寄生组合式继承实例详解
2018/01/06 Javascript
webpack4 处理CSS的方法示例
2018/09/03 Javascript
Vue.js组件间通信方式总结【推荐】
2018/11/23 Javascript
js中实例与对象的区别讲解
2019/01/21 Javascript
Python脚本实时处理log文件的方法
2016/11/21 Python
Python中使用haystack实现django全文检索搜索引擎功能
2017/08/26 Python
简单了解Python生成器是什么
2019/07/02 Python
Python实现微信翻译机器人的方法
2019/08/13 Python
django 取消csrf限制的实例
2020/03/13 Python
解决python使用list()时总是报错的问题
2020/05/05 Python
python3爬虫中多线程进行解锁操作实例
2020/11/25 Python
利用CSS3的特性改变文本选中时的颜色
2013/09/11 HTML / CSS
HTML4和HTML5之间除了相似以外的10个主要不同
2012/12/13 HTML / CSS
美国一家著名的手表在线折扣网站:Discount Watch Store
2020/02/24 全球购物
Smilodox官方运动服装店:从运动服到健身配件
2020/08/27 全球购物
AssertionError 跟一下那个类是 “is – a”的关系
2012/02/21 面试题
给定一个时间点,希望得到其他时间点
2013/11/07 面试题
英语专业毕业个人求职自荐信
2013/09/21 职场文书
新学期决心书
2014/03/11 职场文书
企业宣传标语
2014/06/09 职场文书
教师党员学习群众路线心得体会
2014/11/04 职场文书
cf战队宣传语
2015/07/13 职场文书
停车场管理制度范本
2015/08/05 职场文书