解决 error Component name “index“ should always be multi-word vue/multi-word-component-names

前言

本文主要记录下 vue Eslint 报错 error Component name "index" should always be multi-word vue/multi-word-component-names 的解决方案。

一、报错原因

使用最新 vue-cli 创建项目,npm run serve 运行项目时,报错如下图。

image.png

原因是 eslint-plugin-vue 版本更新了,相较之前版本,@8 版本中新增了不少规则,第一条就是 'vue/multi-word-component-names': 'error', 要求组件名称以驼峰格式命名,所以 index.vue 会报错。


image.png

二、解决方案
按照规则,使用驼峰命名,例如 AppHeader.vue
在 .eslintrc.js 文件中关闭命名规则

// .eslintrc.js
module.exports = {
  root: true,
  env: {
    node: true
  },
  extends: [
    'plugin:vue/vue3-essential',
    '@vue/standard'
  ],
  parserOptions: {
    parser: '@babel/eslint-parser'
  },
  rules: {
    'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
    'indent': 0,
    'space-before-function-paren': 0,

    'vue/multi-word-component-names': [
      'error',
      {
        ignores: ['index'], //需要忽略的组件名
      },
    ]

  }
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容