有没有办法阻止 Vue3 中的单个单词 view 名称从 ESLint 获取错误?
每次运行 ESLint 时,我都会收到以下消息:
1:1 error Component name "About" should always be multi-word vue/multi-word-component-names
我目前有这样的设置:
文件结构:
├── index.html ├── node_modules ├── npm ├── package.json ├── package-lock.json ├── public │ └── favicon.ico ├── README.md ├── src │ ├── App.vue │ ├── assets │ │ └── logo.svg │ ├── components │ │ └── Menu.vue │ ├── env.d.ts │ ├── main.ts │ ├── router │ │ └── index.ts │ └── views │ ├── About.vue │ └── Home.vue ├── tsconfig.json └── vite.config.ts
.eslintrc:
{
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/vue3-essential",
"eslint:recommended",
"@vue/typescript/recommended"
],
"parserOptions": {
"ecmaVersion": 2021
},
"rules": {}
}
package.json
{
...
"scripts": {
"dev": "vite",
"build": "vue-tsc --noEmit && vite build",
"preview": "vite preview",
"lint": "eslint --ext .ts,vue --ignore-path .gitignore ."
},
...
}
Copyright 2014-2025 //m.sbmmt.com/ All Rights Reserved | php.cn | 湘ICP备2023035733号
对于仍然遇到此问题的用户,请在
.eslintrc.js文件中的规则下添加以下内容rules: { ... 'vue/multi-word-component-names': 0, }选项 1:全局禁用
要禁用所有文件中的规则(甚至是
src/components中的文件):选项 2:
在src/views/的 ESLint 配置中覆盖要仅对
src/views/**/*.vue禁用规则,请指定overrides配置:注意:如果将 VS Code 与 ESLint 扩展,重新启动 ESLint 服务器(通过命令面板 a> 的
>ESLint:重新启动 ESLint Server命令)或重新启动 IDE 可能需要重新加载配置。选项 3:
src/views/的目录级配置也可以使用
.eslintrc.js文件在该目录: