首页 > 其他分享 >有关Vue-Cli5.X工程中ESLint组件命名检查问题解决

有关Vue-Cli5.X工程中ESLint组件命名检查问题解决

时间:2023-09-03 11:35:11浏览次数:31  
标签:vue indent html Vue spaces Cli5 found warning ESLint

个人开发环境简介,工具用的Visual Studio Code,因为每个人的开发环境不同,不可能所有解决方案通用,防止踩坑。

PS F:\VueWorkSpace\vue_router_test> node -v
v16.12.0
PS F:\VueWorkSpace\vue_router_test> npm -v
8.1.0
PS F:\VueWorkSpace\vue_router_test> npm eslint -v
8.1.0
PS F:\VueWorkSpace\vue_router_test> vue -V
@vue/cli 5.0.8
PS F:\VueWorkSpace\vue_router_test> npm info vue
[email protected] | MIT | deps: 5 | versions: 445
...(后续省略了)

这几天学习Vue3 Router的时候发现ESLint又他妈抽风了,网上找遍了,CSDN一群傻吊在那里误人子弟,有的直接关掉ESLint语法检查,有的发帖发一半,孩子分段生的,分享一下解决办法,亲测有效,报错如下

PS F:\VueWorkSpace\vue_router_test> npm run serve

> [email protected] serve
> vue-cli-service serve

 INFO  Starting development server...


 ERROR  Failed to compile with 1 error                                                                                                            上午10:48:39

[eslint]
F:\VueWorkSpace\vue_router_test\src\components\Banner.vue
  13:11  error  Component name "Banner" should always be multi-word  vue/multi-word-component-names

✖ 8 problems (1 error, 7 warnings)
  0 errors and 7 warnings potentially fixable with the `--fix` option.


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.
ERROR in [eslint]
F:\VueWorkSpace\vue_router_test\src\components\Banner.vue
  13:11  error  Component name "Banner" should always be multi-word  vue/multi-word-component-names

✖ 8 problems (1 error, 7 warnings)
  0 errors and 7 warnings potentially fixable with the `--fix` option.


webpack compiled with 1 error

解决方案:在./.eslintrc.js里添加如下配置,没有就新建一个,不一定非得是js文件,支持js/json/yaml文件,我这里是Vue官方文档里的示例就是用的js

//官方文档:https://eslint.vuejs.org/user-guide/#installation
module.exports = {
    rules: {
        'vue/multi-word-component-names': 'off'
    }
}

然后重新运行npm run serve就可以了,报Warning是因为缩进不符合ESLint规范,要么改ESLint检查的默认配置,要么调整VsCode的默认缩进

PS F:\VueWorkSpace\vue_router_test> npm run serve

> [email protected] serve
> vue-cli-service serve

 INFO  Starting development server...


 WARNING  Compiled with 1 warning                                                                                                上午11:10:52

[eslint]
F:\VueWorkSpace\vue_router_test\src\App.vue
   2:1   warning  Expected indentation of 2 spaces but found 4 spaces               vue/html-indent
   2:5   warning  Require self-closing on Vue.js custom components (<Banner>)       vue/html-self-closing
   3:1   warning  Expected indentation of 2 spaces but found 4 spaces               vue/html-indent
   4:1   warning  Expected indentation of 4 spaces but found 6 spaces               vue/html-indent
   5:1   warning  Expected indentation of 6 spaces but found 8 spaces               vue/html-indent
   6:1   warning  Expected indentation of 8 spaces but found 10 spaces              vue/html-indent
   6:11  warning  Require self-closing on Vue.js custom components (<router-link>)  vue/html-self-closing
   7:1   warning  Expected indentation of 8 spaces but found 10 spaces              vue/html-indent
   7:11  warning  Require self-closing on Vue.js custom components (<router-link>)  vue/html-self-closing
   8:1   warning  Expected indentation of 6 spaces but found 8 spaces               vue/html-indent
   9:1   warning  Expected indentation of 4 spaces but found 6 spaces               vue/html-indent
  10:1   warning  Expected indentation of 2 spaces but found 4 spaces               vue/html-indent

F:\VueWorkSpace\vue_router_test\src\components\Banner.vue
  2:1  warning  Expected indentation of 2 spaces but found 4 spaces   vue/html-indent
  3:1  warning  Expected indentation of 4 spaces but found 8 spaces   vue/html-indent
  4:1  warning  Expected indentation of 6 spaces but found 12 spaces  vue/html-indent
  5:1  warning  Expected indentation of 8 spaces but found 16 spaces  vue/html-indent
  6:1  warning  Expected indentation of 6 spaces but found 12 spaces  vue/html-indent
  7:1  warning  Expected indentation of 4 spaces but found 8 spaces   vue/html-indent
  8:1  warning  Expected indentation of 2 spaces but found 4 spaces   vue/html-indent

✖ 19 problems (0 errors, 19 warnings)
  0 errors and 19 warnings potentially fixable with the `--fix` option.


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.

  App running at:
  - Local:   http://localhost:8081/
  - Network: http://192.168.12.18:8081/

  Note that the development build is not optimized.
  To create a production build, run npm run build.

标签:vue,indent,html,Vue,spaces,Cli5,found,warning,ESLint
From: https://www.cnblogs.com/sitepoint/p/17674725.html

相关文章

  • vue3中用户登陆会把用户跳转到登录页面,如何让用户登录完成后,跳回原来的页面上
    本地存储在Vue3中,你可以使用VueRouter和sessionStorage或localStorage来实现用户登录后跳回原来的页面。以下是一种常见的实现方式:在用户登录之前,记录当前页面的路由路径:在需要登录的页面组件中,在用户点击登录前,使用 this.$route.path 获取当前页面的路由路径,并将其存......
  • vue前端工程化基础
    1前端工程化1.1前端工程化介绍我们目前的前端开发中,当我们需要使用一些资源时,例如:vue.js,和axios.js文件,都是直接再工程中导入的,如下图所示:但是上述开发模式存在如下问题:每次开发都是从零开始,比较麻烦多个页面中的组件共用性不好js、图片等资源没有规范化的存储目录,没有统......
  • 深入理解 Vuex:Vue 状态管理的核心
    在Vue.js应用程序中,管理组件之间的状态是一项关键任务。为了有效地管理和共享应用程序的数据,Vue.js开发团队开发了一个强大的状态管理库,称为Vuex。本文将深入探讨Vuex的核心概念、用法和最佳实践,帮助您更好地理解和利用这一工具。什么是Vuex?Vuex是一个专为Vue.js设计的状态管理库,......
  • TS 项目加入 ESLint 进行代码检查
    安装依赖npminstalleslint@typescript-eslint/parser@typescript-eslint/eslint-plugin--save-deveslint:ESLint核心包。@typescript-eslint/parser:用于解析TypeScript代码。@typescript-eslint/eslint-plugin:包含一些针对TypeScript的ESLint规则。创建ES......
  • vue 中的html和v-html区别
    <template> <div>2222</div> <p>{{message}}</p> <p>{{rawhtml}}</p> <pv-html="rawhtml"></p></template><script> exportdefault{     data(){         return{             messag......
  • 前端Vue仿企查查天眼查高管信息列表组件
    ​随着技术的不断发展,传统的开发方式使得系统的复杂度越来越高。在传统开发过程中,一个小小的改动或者一个小功能的增加可能会导致整体逻辑的修改,造成牵一发而动全身的情况。为了解决这个问题,我们采用了组件化的开发模式。通过组件化开发,可以有效地实现单独开发,单独维护,而且它们之......
  • 前端Vue仿企查查 天眼查知识产权标准信息列表组件
    ​引入Vue仿企查查天眼查知识产权标准信息列表组件随着技术的不断发展,传统的开发方式使得系统的复杂度越来越高。在传统开发过程中,一个小小的改动或者一个小功能的增加可能会导致整体逻辑的修改,造成牵一发而动全身的情况。为了解决这个问题,我们采用了组件化的开发模式。通过组件......
  • 2、Vue中安装element-plus
    1、在项目终端命令行中输入:pnpminstallelement-plus--save 2、项目中导入elementimportElementPlusfrom'element-plus'import'element-plus/dist/index.css' 3、使用element组件 ......
  • vue项目中全局引入cass(scss)变量和sass(scss) mixin
    1、使用场景variable.scss文件样例//颜色定义规范$color-background:#222;mixin.scss文件样例//背景图片@mixinbg-image($url){background-image:url($url+"@2x.png");@media(-webkit-min-device-pixel-ratio:3),(min-device-pixel-ratio:3){background-i......
  • vue --version 运行出现throw new ERR_SYSTEM_ERROR 错误
    (1)根据错误提示信息,找到出错入口文件:E:\SVN\zlpt\node_modules\node-ipc\entities\Defaults.js然后指定位置添加如下代码即可:constos=require('os');os.hostname=()=>"localhost";......