vue/valid-v-slot
强制执行有效的
v-slot
指令
- ⚙️ 此规则包含在所有
"plugin:vue/vue3-essential"
、*.configs["flat/essential"]
、"plugin:vue/essential"
、*.configs["flat/vue2-essential"]
、"plugin:vue/vue3-strongly-recommended"
、*.configs["flat/strongly-recommended"]
、"plugin:vue/strongly-recommended"
、*.configs["flat/vue2-strongly-recommended"]
、"plugin:vue/vue3-recommended"
、*.configs["flat/recommended"]
、"plugin:vue/recommended"
和*.configs["flat/vue2-recommended"]
中。
此规则检查每个 v-slot
指令是否有效。
📖 规则详情
此规则在以下情况下报告 v-slot
指令
- 该指令不属于自定义元素。例如
<div v-slot=""></div>
- 该指令是一个命名插槽,并且直接位于自定义元素上。例如
<my-component v-slot:foo></my-component>
- 该指令是默认插槽,直接位于自定义元素上,并且还有其他命名插槽。例如
<my-component v-slot=""><template v-slot:foo></template></my-component>
- 具有该指令的元素具有另一个
v-slot
指令。例如<my-component v-slot:one v-slot:two></my-component>
- 具有该指令的元素具有另一个
v-slot
指令,该指令被分发到同一个插槽。例如<my-component><template v-slot:foo></template><template v-slot:foo></template></my-component>
- 该指令具有一个动态参数,该参数使用该指令定义的作用域属性。例如
<my-component><template v-slot:[data]="data"></template></my-component>
- 该指令具有任何修饰符。例如
<my-component v-slot.foo></my-component>
- 该指令是默认插槽,直接位于自定义元素上,并且没有值。例如
<my-component v-slot></my-component>
注意
此规则不检查指令中的语法错误,因为这些错误由 vue/no-parsing-error 规则检查。
🔧 选项
json
{
"vue/valid-v-slot": ["error", {
"allowModifiers": false
}]
}
allowModifiers
(boolean
) ... 允许在v-slot
指令的参数中使用修饰符。紧跟在v-slot
之后的修饰符仍然是不允许的。例如<template v-slot.foo>
默认为false
。
allowModifiers: true
👫 相关规则
🚀 版本
此规则是在 eslint-plugin-vue v7.0.0 中引入的。