Appearance
可用规则
¥Available rules
图例
🔧表示该规则是可修复的,并且在 命令行 上使用 --fix
选项可以自动修复一些报告的问题。
¥🔧 Indicates that the rule is fixable, and using --fix
option on the command line can automatically fix some of the reported problems.
💡表示规则报告的某些问题可以由编辑器 suggestions 手动修复。
¥💡 Indicates that some problems reported by the rule are manually fixable by editor suggestions.
表示规则类型的标记:
¥Mark indicating rule type:
⚠️ 可能的问题:这些规则与代码中可能出现的逻辑错误有关。
¥⚠️ Possible Problems: These rules relate to possible logic errors in code.
🔨建议:这些规则建议采用其他方式。
¥🔨 Suggestions: These rules suggest alternate ways of doing things.
💄布局和格式:这些规则关心的是代码的外观,而不是代码的执行方式。
¥💄 Layout & Formatting: These rules care about how the code looks rather than how it executes.
基本规则(启用正确的 ESLint 解析)
¥Base Rules (Enabling Correct ESLint Parsing)
此类别中的规则适用于 eslint-plugin-vue 提供的所有预设。
¥Rules in this category are enabled for all presets provided by eslint-plugin-vue.
规则 ID | 描述 | ||
---|---|---|---|
vue/comment-directive | 支持 <template> 中的注释指令 | ⚠️ | |
vue/jsx-uses-vars | 防止在 JSX 中使用的变量被标记为未使用 | ⚠️ |
优先级 A:必备(错误预防)
¥Priority A: Essential (Error Prevention)
3️⃣表示该规则适用于 Vue 3,并包含在所有
"plugin:vue/essential"
、*.configs["flat/essential"]
、"plugin:vue/strongly-recommended"
、*.configs["flat/strongly-recommended"]
、"plugin:vue/recommended"
和*.configs["flat/recommended"]
预设中。¥3️⃣ Indicates that the rule is for Vue 3 and is included in all of
"plugin:vue/essential"
,*.configs["flat/essential"]
,"plugin:vue/strongly-recommended"
,*.configs["flat/strongly-recommended"]
,"plugin:vue/recommended"
and*.configs["flat/recommended"]
presets.2️⃣表示该规则适用于 Vue 2,并包含在所有
"plugin:vue/vue2-essential"
、*.configs["flat/vue2-essential"]
、"plugin:vue/vue2-strongly-recommended"
、*.configs["flat/vue2-strongly-recommended"]
和"plugin:vue/vue2-recommended"
、*.configs["flat/vue2-recommended"]
预设中。¥2️⃣ Indicates that the rule is for Vue 2 and is included in all of
"plugin:vue/vue2-essential"
,*.configs["flat/vue2-essential"]
,"plugin:vue/vue2-strongly-recommended"
,*.configs["flat/vue2-strongly-recommended"]
and"plugin:vue/vue2-recommended"
,*.configs["flat/vue2-recommended"]
presets.
规则 ID | 描述 | ||
---|---|---|---|
vue/multi-word-component-names | 要求组件名称始终为多字 | 3️⃣2️⃣🔨 | |
vue/no-arrow-functions-in-watch | 禁止使用箭头函数定义观察者 | 3️⃣2️⃣⚠️ | |
vue/no-async-in-computed-properties | 禁止在计算属性中执行异步操作 | 3️⃣2️⃣⚠️ | |
vue/no-child-content | 禁止元素的子内容被 v-html 或 v-text 等指令覆盖 | 💡 | 3️⃣2️⃣⚠️ |
vue/no-computed-properties-in-data | 禁止访问 data 中的计算属性 | 3️⃣2️⃣⚠️ | |
vue/no-custom-modifiers-on-v-model | 禁止在组件上使用 v-model 的自定义修饰符 | 2️⃣⚠️ | |
vue/no-deprecated-data-object-declaration | 禁止在数据上使用已弃用的对象声明(在 Vue.js 3.0.0+ 中) | 🔧 | 3️⃣⚠️ |
vue/no-deprecated-delete-set | 禁止使用已弃用的 $delete 和 $set (在 Vue.js 3.0.0+ 中) | 3️⃣⚠️ | |
vue/no-deprecated-destroyed-lifecycle | 禁止使用已弃用的 destroyed 和 beforeDestroy 生命周期钩子(在 Vue.js 3.0.0+ 中) | 🔧 | 3️⃣⚠️ |
vue/no-deprecated-dollar-listeners-api | 禁止使用已弃用的 $listeners (在 Vue.js 3.0.0+ 中) | 3️⃣⚠️ | |
vue/no-deprecated-dollar-scopedslots-api | 禁止使用已弃用的 $scopedSlots (在 Vue.js 3.0.0+ 中) | 🔧 | 3️⃣⚠️ |
vue/no-deprecated-events-api | 禁止使用已弃用的事件 api(在 Vue.js 3.0.0+ 中) | 3️⃣⚠️ | |
vue/no-deprecated-filter | 禁止使用已弃用的过滤器语法(在 Vue.js 3.0.0+ 中) | 3️⃣⚠️ | |
vue/no-deprecated-functional-template | 禁止使用弃用 functional 模板(在 Vue.js 3.0.0+ 中) | 3️⃣⚠️ | |
vue/no-deprecated-html-element-is | 禁止在 HTML 元素上使用已弃用的 is 属性(在 Vue.js 3.0.0+ 中) | 3️⃣⚠️ | |
vue/no-deprecated-inline-template | 禁止使用已弃用的 inline-template 属性(在 Vue.js 中 3.0.0+) | 3️⃣⚠️ | |
vue/no-deprecated-model-definition | 禁止弃用的 model 定义(在 Vue.js 3.0.0+ 中) | 💡 | 3️⃣⚠️ |
vue/no-deprecated-props-default-this | 禁止在 props 默认函数中访问弃用的 this (在 Vue.js 3.0.0+ 中) | 3️⃣⚠️ | |
vue/no-deprecated-router-link-tag-prop | 禁止在 RouterLink 上使用已弃用的 tag 属性(在 Vue.js 3.0.0+ 中) | 3️⃣⚠️ | |
vue/no-deprecated-scope-attribute | 禁止弃用的 scope 属性(在 Vue.js 2.5.0+ 中) | 🔧 | 3️⃣🔨 |
vue/no-deprecated-slot-attribute | 禁止弃用的 slot 属性(在 Vue.js 2.6.0+ 中) | 🔧 | 3️⃣🔨 |
vue/no-deprecated-slot-scope-attribute | 禁止弃用的 slot-scope 属性(在 Vue.js 2.6.0+ 中) | 🔧 | 3️⃣🔨 |
vue/no-deprecated-v-bind-sync | 禁止在 v-bind 指令上使用已弃用的 .sync 修饰符(在 Vue.js 3.0.0+ 中) | 🔧 | 3️⃣⚠️ |
vue/no-deprecated-v-is | 禁止弃用的 v-is 指令(在 Vue.js 3.1.0+ 中) | 3️⃣🔨 | |
vue/no-deprecated-v-on-native-modifier | 禁止使用已弃用的 .native 修饰符(在 Vue.js 3.0.0+ 中) | 3️⃣⚠️ | |
vue/no-deprecated-v-on-number-modifiers | 禁止使用已弃用的数字(键码)修饰符(在 Vue.js 3.0.0+ 中) | 🔧 | 3️⃣⚠️ |
vue/no-deprecated-vue-config-keycodes | 禁止使用已弃用的 Vue.config.keyCodes (在 Vue.js 3.0.0+ 中) | 3️⃣⚠️ | |
vue/no-dupe-keys | 禁止字段名称重复 | 3️⃣2️⃣⚠️ | |
vue/no-dupe-v-else-if | 禁止在 v-if / v-else-if 链中出现重复条件 | 3️⃣2️⃣⚠️ | |
vue/no-duplicate-attributes | 禁止属性重复 | 3️⃣2️⃣⚠️ | |
vue/no-export-in-script-setup | 禁止 <script setup> 中的 export | 3️⃣2️⃣⚠️ | |
vue/no-expose-after-await | 禁止异步注册的 expose | 3️⃣⚠️ | |
vue/no-lifecycle-after-await | 禁止异步注册生命周期钩子 | 3️⃣🔨 | |
vue/no-multiple-template-root | 禁止向模板添加多个根节点 | 2️⃣⚠️ | |
vue/no-mutating-props | 禁止组件 props 的修改 | 3️⃣2️⃣🔨 | |
vue/no-parsing-error | 禁止在 <template> 中解析错误 | 3️⃣2️⃣⚠️ | |
vue/no-ref-as-operand | 禁止使用 ref() (Composition API)封装的值作为操作数 | 🔧 | 3️⃣2️⃣🔨 |
vue/no-reserved-component-names | 禁止组件定义中保留名称的使用 | 3️⃣2️⃣🔨 | |
vue/no-reserved-keys | 禁止覆盖保留键 | 3️⃣2️⃣🔨 | |
vue/no-reserved-props | 禁止在 props 中保留名称 | 3️⃣2️⃣⚠️ | |
vue/no-shared-component-data | 强制组件的数据属性为函数 | 🔧 | 3️⃣2️⃣⚠️ |
vue/no-side-effects-in-computed-properties | 禁止计算属性中的副作用 | 3️⃣2️⃣⚠️ | |
vue/no-template-key | 禁止在 <template> 上使用 key 属性 | 3️⃣2️⃣⚠️ | |
vue/no-textarea-mustache | 禁止 <textarea> 中的胡须 | 3️⃣2️⃣⚠️ | |
vue/no-unused-components | 禁止注册模板中未使用的组件 | 3️⃣2️⃣🔨 | |
vue/no-unused-vars | 禁止未使用的 v-for 指令或范围属性变量定义 | 💡 | 3️⃣2️⃣🔨 |
vue/no-use-computed-property-like-method | 禁止使用方法等计算属性 | 3️⃣2️⃣⚠️ | |
vue/no-use-v-if-with-v-for | 禁止在与 v-for 相同的元素上使用 v-if | 3️⃣2️⃣🔨 | |
vue/no-useless-template-attributes | 禁止在 <template> 上使用无用属性 | 3️⃣2️⃣⚠️ | |
vue/no-v-for-template-key-on-child | 禁止将 <template v-for> 的键放在子元素上 | 3️⃣⚠️ | |
vue/no-v-for-template-key | 禁止在 <template v-for> 上使用 key 属性 | :no_entry_sign: | 2️⃣⚠️ |
vue/no-v-model-argument | 禁止向自定义组件中使用的 v-model 添加参数 | :no_entry_sign: | 2️⃣⚠️ |
vue/no-v-text-v-html-on-component | 禁止组件上的 v-text / v-html | 3️⃣2️⃣⚠️ | |
vue/no-watch-after-await | 禁止异步注册的 watch | 3️⃣🔨 | |
vue/prefer-import-from-vue | 强制从 'vue' 导入,而不是从 '@vue/*' 导入 | 🔧 | 3️⃣🔨 |
vue/require-component-is | 要求 <component> 元素中的 v-bind:is | 3️⃣2️⃣⚠️ | |
vue/require-prop-type-constructor | 要求 prop 类型为构造函数 | 🔧 | 3️⃣2️⃣🔨 |
vue/require-render-return | 强制渲染函数始终返回值 | 3️⃣2️⃣⚠️ | |
vue/require-slots-as-functions | 强制 $slots 的属性用作函数 | 3️⃣⚠️ | |
vue/require-toggle-inside-transition | 要求控制 <transition> 内内容的显示 | 3️⃣⚠️ | |
vue/require-v-for-key | 要求 v-bind:key 带有 v-for 指令 | 3️⃣2️⃣⚠️ | |
vue/require-valid-default-prop | 强制 props 默认值有效 | 3️⃣2️⃣🔨 | |
vue/return-in-computed-property | 强制在计算属性中存在 return 语句 | 3️⃣2️⃣⚠️ | |
vue/return-in-emits-validator | 强制在 emits 验证器中存在 return 语句 | 3️⃣2️⃣⚠️ | |
vue/use-v-on-exact | 强制在 v-on 上使用 exact 修饰符 | 3️⃣2️⃣🔨 | |
vue/valid-attribute-name | 要求有效的属性名称 | 3️⃣2️⃣⚠️ | |
vue/valid-define-emits | 强制使用有效的 defineEmits 编译器宏 | 3️⃣2️⃣⚠️ | |
vue/valid-define-options | 强制使用有效的 defineOptions 编译器宏 | 3️⃣⚠️ | |
vue/valid-define-props | 强制使用有效的 defineProps 编译器宏 | 3️⃣2️⃣⚠️ | |
vue/valid-model-definition | 要求模型选项中有有效键 | :no_entry_sign: | 2️⃣⚠️ |
vue/valid-next-tick | 强制使用有效的 nextTick 函数调用 | 🔧💡 | 3️⃣2️⃣⚠️ |
vue/valid-template-root | 强制有效的模板根 | 3️⃣2️⃣⚠️ | |
vue/valid-v-bind-sync | 在 v-bind 指令上强制使用有效的 .sync 修饰符 | :no_entry_sign: | 2️⃣⚠️ |
vue/valid-v-bind | 强制有效的 v-bind 指令 | 3️⃣2️⃣⚠️ | |
vue/valid-v-cloak | 强制有效的 v-cloak 指令 | 3️⃣2️⃣⚠️ | |
vue/valid-v-else-if | 强制有效的 v-else-if 指令 | 3️⃣2️⃣⚠️ | |
vue/valid-v-else | 强制有效的 v-else 指令 | 3️⃣2️⃣⚠️ | |
vue/valid-v-for | 强制有效的 v-for 指令 | 3️⃣2️⃣⚠️ | |
vue/valid-v-html | 强制有效的 v-html 指令 | 3️⃣2️⃣⚠️ | |
vue/valid-v-if | 强制有效的 v-if 指令 | 3️⃣2️⃣⚠️ | |
vue/valid-v-is | 强制有效的 v-is 指令 | 3️⃣⚠️ | |
vue/valid-v-memo | 强制有效的 v-memo 指令 | 3️⃣⚠️ | |
vue/valid-v-model | 强制有效的 v-model 指令 | 3️⃣2️⃣⚠️ | |
vue/valid-v-on | 强制有效的 v-on 指令 | 3️⃣2️⃣⚠️ | |
vue/valid-v-once | 强制有效的 v-once 指令 | 3️⃣2️⃣⚠️ | |
vue/valid-v-pre | 强制有效的 v-pre 指令 | 3️⃣2️⃣⚠️ | |
vue/valid-v-show | 强制有效的 v-show 指令 | 3️⃣2️⃣⚠️ | |
vue/valid-v-slot | 强制有效的 v-slot 指令 | 3️⃣2️⃣⚠️ | |
vue/valid-v-text | 强制有效的 v-text 指令 | 3️⃣2️⃣⚠️ |
优先级 B:强烈推荐(提高可读性)
¥Priority B: Strongly Recommended (Improving Readability)
3️⃣表示该规则适用于 Vue 3,并包含在所有
"plugin:vue/strongly-recommended"
、*.configs["flat/strongly-recommended"]
、"plugin:vue/recommended"
和*.configs["flat/recommended"]
预设中。¥3️⃣ Indicates that the rule is for Vue 3 and is included in all of
"plugin:vue/strongly-recommended"
,*.configs["flat/strongly-recommended"]
,"plugin:vue/recommended"
and*.configs["flat/recommended"]
presets.2️⃣表示该规则适用于 Vue 2,并包含在
"plugin:vue/vue2-strongly-recommended"
、*.configs["flat/vue2-strongly-recommended"]
和"plugin:vue/vue2-recommended"
、*.configs["flat/vue2-recommended"]
预设中。¥2️⃣ Indicates that the rule is for Vue 2 and is included in
"plugin:vue/vue2-strongly-recommended"
,*.configs["flat/vue2-strongly-recommended"]
and"plugin:vue/vue2-recommended"
,*.configs["flat/vue2-recommended"]
presets.
优先级 C:推荐(潜在危险模式)
¥Priority C: Recommended (Potentially Dangerous Patterns)
3️⃣表示该规则适用于 Vue 3,并包含在
"plugin:vue/recommended"
和*.configs["flat/recommended"]
预设中。¥3️⃣ Indicates that the rule is for Vue 3 and is included in
"plugin:vue/recommended"
and*.configs["flat/recommended"]
presets.2️⃣表示该规则适用于 Vue 2,并包含在
"plugin:vue/vue2-recommended"
、*.configs["flat/vue2-recommended"]
预设中。¥2️⃣ Indicates that the rule is for Vue 2 and is included in
"plugin:vue/vue2-recommended"
,*.configs["flat/vue2-recommended"]
preset.
规则 ID | 描述 | ||
---|---|---|---|
vue/attributes-order | 强制属性顺序 | 🔧 | 3️⃣2️⃣🔨 |
vue/block-order | 强制组件顶层元素的顺序 | 🔧 | 3️⃣2️⃣🔨 |
vue/no-lone-template | 禁止不必要的 <template> | 3️⃣2️⃣⚠️ | |
vue/no-multiple-slot-args | 禁止将多个参数传递给作用域插槽 | 3️⃣2️⃣⚠️ | |
vue/no-required-prop-with-default | 强制使用默认值的 props 为可选 | 🔧💡 | 3️⃣2️⃣⚠️ |
vue/no-v-html | 禁止使用 v-html 来防止 XSS 攻击 | 3️⃣2️⃣🔨 | |
vue/order-in-components | 强制组件中属性的顺序 | 🔧💡 | 3️⃣2️⃣🔨 |
vue/this-in-template | 禁止在模板中使用 this | 🔧 | 3️⃣2️⃣🔨 |
未分类
¥Uncategorized
没有预设启用此类别中的规则。如果你愿意,请启用每条规则。
¥No preset enables the rules in this category. Please enable each rule if you want.
例如:
¥For example:
json
{
"rules": {
"vue/block-lang": "error"
}
}
扩展规则
¥Extension Rules
以下规则扩展了 ESLint 本身提供的规则,并将其应用于 <template>
中的表达式。
¥The following rules extend the rules provided by ESLint itself and apply them to the expressions in the <template>
.
规则 ID | 描述 | ||
---|---|---|---|
vue/array-bracket-newline | 在 <template> 中强制在数组括号打开后和关闭前换行 | 🔧 | 💄 |
vue/array-bracket-spacing | 在 <template> 中强制使用数组括号内的一致间距 | 🔧 | 💄 |
vue/array-element-newline | 在 <template> 中强制每个数组元素后换行 | 🔧 | 💄 |
vue/arrow-spacing | 在 <template> 中强制使用箭头函数中箭头前后的一致间距 | 🔧 | 💄 |
vue/block-spacing | 在 <template> 中禁止或强制在打开块之后和关闭块之前在块内使用空格 | 🔧 | 💄 |
vue/brace-style | 在 <template> 中强制使用块的一致括号样式 | 🔧 | 💄 |
vue/camelcase | 在 中强制使用驼峰命名约定 <template> | 🔨 | |
vue/comma-dangle | 在 <template> 中要求或禁止使用尾随逗号 | 🔧 | 💄 |
vue/comma-spacing | 在 <template> 中强制使用逗号前后的一致间距 | 🔧 | 💄 |
vue/comma-style | 在 <template> 中强制使用逗号样式 | 🔧 | 💄 |
vue/dot-location | 在 <template> 中强制使用点前后的一致换行符 | 🔧 | 💄 |
vue/dot-notation | 在 <template> 中尽可能强制使用点符号 | 🔧 | 🔨 |
vue/eqeqeq | 要求在 <template> 中使用 === 和 !== | 🔧 | 🔨 |
vue/func-call-spacing | 在 <template> 中要求或禁止在函数标识符及其调用之间留有空格 | 🔧 | 💄 |
vue/key-spacing | 在 <template> 中强制使用类型和接口中属性名称和类型注释之间的一致间距 | 🔧 | 💄 |
vue/keyword-spacing | 在 <template> 中强制使用关键字前后的一致间距 | 🔧 | 💄 |
vue/max-len | 强制 .vue 文件中的最大行长度 | 💄 | |
vue/multiline-ternary | 在 <template> 中强制在三元表达式的操作数之间使用换行符 | 🔧 | 💄 |
vue/no-console | 在 <template> 中禁止使用 console | 💡 | 🔨 |
vue/no-constant-condition | 在 <template> 中禁止条件中的常量表达式 | ⚠️ | |
vue/no-empty-pattern | 在 <template> 中禁止空解构模式 | ⚠️ | |
vue/no-extra-parens | 在 <template> 中禁止不必要的括号 | 🔧 | 💄 |
vue/no-implicit-coercion | 在 <template> 中禁止简写类型转换 | 🔧 | 🔨 |
vue/no-irregular-whitespace | 禁止在 .vue 中出现不规则空格文件 | ⚠️ | |
vue/no-loss-of-precision | 在 <template> 中禁止丢失精度的字面量数字 | ⚠️ | |
vue/no-restricted-syntax | 在 <template> 中禁止指定语法 | 🔨 | |
vue/no-sparse-arrays | 在 <template> 中禁止稀疏数组 | ⚠️ | |
vue/no-useless-concat | 在 <template> 中禁止不必要的字面量或模板字面量连接 | 🔨 | |
vue/object-curly-newline | 在 <template> 中强制使用开括号后和闭括号前的一致换行符 | 🔧 | 💄 |
vue/object-curly-spacing | 在 <template> | 🔧 | 💄 |
vue/object-property-newline | 在 <template> 中强制将对象属性放在单独的行上 | 🔧 | 💄 |
vue/object-shorthand | 在 <template> 中要求或禁止对象字面量的方法和属性简写语法 | 🔧 | 🔨 |
vue/operator-linebreak | 在 <template> 中强制使用运算符的一致换行符样式 | 🔧 | 💄 |
vue/prefer-template | 要求在 <template> 中使用模板字面量而不是字符串连接 | 🔧 | 🔨 |
vue/quote-props | 在 <template> 中要求在对象字面量、类型字面量、接口和枚举属性名称周围使用引号 <template> | 🔧 | 💄 |
vue/space-in-parens | 在 <template> 中强制括号内间距一致 | 🔧 | 💄 |
vue/space-infix-ops | 要求在 <template> 中在中缀运算符周围留有空格 | 🔧 | 💄 |
vue/space-unary-ops | 在 <template> 中强制使用一元运算符前后的一致间距 | 🔧 | 💄 |
vue/template-curly-spacing | 在 <template> 中要求或禁止在模板字符串的嵌入表达式周围留有空格 | 🔧 | 💄 |
已弃用
¥Deprecated
🚫我们将在下一个主要版本中删除弃用的规则。请迁移到后继/新规则。
¥🚫 We're going to remove deprecated rules in the next major release. Please migrate to successor/new rules.
😇由于资源不足,我们不会修复弃用规则中的错误。
¥😇 We don't fix bugs which are in deprecated rules since we don't have enough resources.
规则 ID | 替换为 |
---|---|
vue/no-v-for-template-key | (无替换) |
vue/no-v-model-argument | (无替换) |
vue/valid-model-definition | (无替换) |
vue/valid-v-bind-sync | (无替换) |
已删除
¥Removed
⛔这些规则在弃用一段时间后,已在之前的主要版本中删除。
¥⛔ These rules have been removed in a previous major release, after they have been deprecated for a while.
规则 ID | 替换为 | 版本中已弃用 | 在版本中删除 |
---|---|---|---|
vue/component-tags-order | vue/block-order | [v9.16.0] | [v10.0.0] |
vue/experimental-script-setup-vars | (无替换) | [v7.13.0] | [v9.0.0] |
vue/name-property-casing | vue/component-definition-name-casing | [v7.0.0] | [v9.0.0] |
vue/no-confusing-v-for-v-if | vue/no-use-v-if-with-v-for | [v5.0.0] | [v9.0.0] |
vue/no-invalid-model-keys | vue/valid-model-definition | [v9.0.0] | [v10.0.0] |
vue/no-ref-object-destructure | vue/no-ref-object-reactivity-loss | [v9.17.0] | [v10.0.0] |
vue/no-setup-props-destructure | vue/no-setup-props-reactivity-loss | [v9.17.0] | [v10.0.0] |
vue/no-unregistered-components | vue/no-undef-components | [v8.4.0] | [v9.0.0] |
vue/script-setup-uses-vars | (无替换) | [v9.0.0] | [v10.0.0] |
vue/v-on-function-call | vue/v-on-handler-style | [v9.7.0] | [v10.0.0] |