详解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"代码
Jan 09 Javascript
Extjs学习笔记之八 继承和事件基础
Jan 08 Javascript
jquery中获得$.ajax()事件返回的值并添加事件的方法
Apr 15 Javascript
Jqyery中同等与js中windows.onload的应用
May 10 Javascript
JavaScript实现在数组中查找不同顺序排列的字符串
Sep 26 Javascript
jquery让指定的元素闪烁显示的方法
Mar 17 Javascript
jQuery+PHP+Mysql实现抽奖程序
Apr 12 jQuery
jQuery选择器之属性过滤选择器详解
Sep 28 jQuery
微信小程序使用map组件实现获取定位城市天气或者指定城市天气数据功能
Jan 22 Javascript
原生javascript的ajax请求及后台PHP响应操作示例
Feb 24 Javascript
基于原生js实现九宫格算法代码实例
Jul 03 Javascript
原生JS实现多条件筛选
Aug 19 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 面向对象 final类与final方法
2010/05/05 PHP
php中存储用户ID和密码到mysql数据库的方法
2013/02/06 PHP
formValidator3.3的ajaxValidator一些异常分析
2011/07/12 Javascript
jQuery1.6 使用方法二
2011/11/23 Javascript
浅析js中取绝对值的2种方法
2013/07/09 Javascript
Select标签下拉列表二级联动级联实例代码
2014/02/07 Javascript
jQuery动态创建html元素的常用方法汇总
2014/09/05 Javascript
简单实现JS倒计时效果
2016/12/23 Javascript
JS传参及动态修改页面布局
2017/04/13 Javascript
React简单介绍
2017/05/24 Javascript
JavaScript原生实现观察者模式的示例
2017/12/15 Javascript
javaScript动态添加Li元素的实例
2018/02/24 Javascript
node打造微信个人号机器人的方法示例
2018/04/26 Javascript
vue-cli中vue本地实现跨域调试接口
2019/01/16 Javascript
python Django连接MySQL数据库做增删改查
2013/11/07 Python
python实现得到一个给定类的虚函数
2014/09/28 Python
在Python中使用swapCase()方法转换大小写的教程
2015/05/20 Python
Python实现建立SSH连接的方法
2015/06/03 Python
python 打印出所有的对象/模块的属性(实例代码)
2016/09/11 Python
python使用xlrd模块读取xlsx文件中的ip方法
2019/01/11 Python
Pycharm以root权限运行脚本的方法
2019/01/19 Python
Django框架模板的使用方法示例
2019/05/25 Python
解决Django 在ForeignKey中出现 non-nullable field错误的问题
2019/08/06 Python
Pytorch提取模型特征向量保存至csv的例子
2020/01/03 Python
Python 日期与时间转换的方法
2020/08/01 Python
localStorage的过期时间设置的方法详解
2018/11/26 HTML / CSS
韩国三星旗下的一家超市连锁店:Home Plus
2016/07/30 全球购物
英国现代家具和照明购物网站:Heal’s
2019/10/30 全球购物
马来西亚在线购物:POPLOOK.com
2019/12/09 全球购物
个人自我鉴定
2013/11/07 职场文书
某同学的自我鉴定范文
2013/12/26 职场文书
公安个人四风问题对照检查及整改措施
2014/10/28 职场文书
房屋产权共有协议书范本
2014/11/03 职场文书
2019年市场部个人述职报告(三篇)
2019/10/23 职场文书
Pyqt5将多个类组合在一个界面显示的完整示例
2021/09/04 Python
Android Gradle 插件自定义Plugin实现注意事项
2022/06/16 Java/Android