有沒有辦法阻止 Vue3 中的單字 view 名稱從 ESLint 取得錯(cuò)誤?
每次執(zhí)行 ESLint 時(shí),我都會(huì)收到以下訊息:
1:1 error Component name "About" should always be multi-word vue/multi-word-component-names
我目前有這樣的設(shè)定:
檔案結(jié)構(gòu):
├── 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 ." }, ... }
對(duì)於仍遇到此問題的用戶,請(qǐng)?jiān)?.eslintrc.js
檔案中的規(guī)則下新增以下內(nèi)容
rules: { ... 'vue/multi-word-component-names': 0, }
要停用所有檔案中的規(guī)則(甚至是 src/components
中的檔案):
///.eslintrc.js module.exports = { ? rules: { 'vue/multi-word-component-names': 0, }, }
在 src/views/
的 ESLint 配置中覆寫
要只對(duì)src/views/**/*.vue
停用規(guī)則,請(qǐng)指定 overrides
設(shè)定:
///.eslintrc.js module.exports = { ? overrides: [ { files: ['src/views/**/*.vue'], rules: { 'vue/multi-word-component-names': 0, }, }, ], }
注意:如果將VS Code 與ESLint 擴(kuò)展,重新啟動(dòng)ESLint 伺服器(透過命令面板 a> 的>ESLint:重新啟動(dòng)ESLint Server
指令)或重新啟動(dòng)IDE 可能需要重新載入設(shè)定。
src/views/
的目錄級(jí)配置也可以使用 src/views/**/*.vue 的規(guī)則設(shè)定檔" rel="noreferrer">.eslintrc.js
檔案在該目錄:
///src/views/.eslintrc.js module.exports = { rules: { 'vue/multi-word-component-names': 0, }, }