【vue eslint】报错error Component name “index“ should always be multi-word vue/multi-word-component-names的相关解决办法

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

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

error Component name "index" should always be multi-word vue/multi-word-component-names

原因是 eslint-plugin-vue 版本更新了,相较之前版本,@8 版本中新增了不少规则,第一条就是 'vue/multi-word-component-names': 'error', 要求组件名称以驼峰格式命名,自定义组件名称应该由多单词组成,防止和html标签冲突,所以 index.vue 会报错。

解决方案:

1、按照规则,使用驼峰命名,例如 AppIndex.vue

2、在 .eslintrc.js 文件中关闭命名规则

// .eslintrc.js
module.exports = {
  root: true,
  env: {
    node: true,
  },
  extends: [
    "plugin:vue/essential",
    "eslint:recommended",
    "@vue/typescript"
  ],
  parserOptions: {
    "parser": "@typescript-eslint/parser"
  },
  rules: {
    "vue/multi-word-component-names": [
      "error",
      {
        ignores: ["index"], //需要忽略的组件名
      },
    ],
  },
};

以上这篇【vue eslint】报错error Component name “index“ should always be multi-word vue/multi-word-component-names的相关解决办法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持芦苇派。

原创文章,作者:ECHO陈文,如若转载,请注明出处:https://www.luweipai.cn/html/1669988487/

  • 1