详解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 相关文章推荐
动态加载iframe
Jun 16 Javascript
javascript while语句和do while语句的区别分析
Dec 08 Javascript
Javascript继承机制的设计思想分享
Aug 28 Javascript
js点击更换背景颜色或图片的实例代码
Jun 25 Javascript
js和jquery设置disabled属性为true使按钮失效
Aug 07 Javascript
javascript实现tab切换的两个实例
Nov 05 Javascript
深入浅析JavaScript中prototype和proto的关系
Nov 15 Javascript
深入php面向对象、模式与实践
Feb 16 Javascript
js仿3366小游戏选字游戏
Apr 14 Javascript
100行代码理解和分析vue2.0响应式架构
Mar 09 Javascript
浅析Angular19 自定义表单控件
Jan 31 Javascript
详解vue组件之间的通信
Aug 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
上海地方志办公室-上海电子仪表工业志
2021/03/04 无线电
php使用preg_match()函数验证ip地址的方法
2017/01/07 PHP
jQuery的.live()和.die() 使用介绍
2011/09/10 Javascript
js从Cookies里面取值的简单实现
2014/06/30 Javascript
jQuery源码分析之jQuery中的循环技巧详解
2014/09/06 Javascript
javascript数组输出的两种方式
2015/01/13 Javascript
js实现延迟加载的方法
2015/06/24 Javascript
js print打印网页指定区域内容的简单实例
2016/11/01 Javascript
EasyUI学习之DataGird分页显示数据
2016/12/29 Javascript
基于vue+ bootstrap实现图片上传图片展示功能
2017/05/17 Javascript
jQuery实现图片上传预览效果功能完整实例【测试可用】
2018/05/28 jQuery
解决layui动态加载复选框无法选中的问题
2019/09/20 Javascript
js实现html滑动图片拼图验证
2020/06/24 Javascript
vue实现的多页面项目如何优化打包的步骤详解
2020/07/19 Javascript
Python构造自定义方法来美化字典结构输出的示例
2016/06/16 Python
使用python绘制3维正态分布图的方法
2018/12/29 Python
Python之Numpy的超实用基础详细教程
2019/10/23 Python
python 引用传递和值传递详解(实参,形参)
2020/06/05 Python
Node.js 和 Python之间该选择哪个?
2020/08/05 Python
Django实现随机图形验证码的示例
2020/10/15 Python
关于HTML5语义标签的实践(blog页面)
2016/07/12 HTML / CSS
韩国休闲女装品牌网站:ANAIS
2016/08/24 全球购物
中国排名第一的外贸销售网站:LightInTheBox.com(兰亭集势)
2016/10/28 全球购物
缴纳养老保险的证明
2014/01/10 职场文书
毕业生如何写自我鉴定
2014/03/15 职场文书
小小商店教学反思
2014/04/27 职场文书
小学教师师德师风自我剖析材料
2014/09/29 职场文书
大学生求职信怎么写
2015/03/19 职场文书
2015年度绩效考核工作总结
2015/05/27 职场文书
2015年六年级班主任工作总结
2015/10/15 职场文书
心理健康教育培训研修感言
2015/11/18 职场文书
2016中秋节月饼促销广告语
2016/01/28 职场文书
五年级作文之劳动作文
2019/11/12 职场文书
CSS3实现列表无限滚动/轮播效果
2021/06/23 HTML / CSS
Golang 遍历二叉树
2022/04/19 Golang
Android开发 使用文件储存的方式保存QQ密码
2022/04/24 Java/Android