Appearance
vue/require-explicit-emits
要求
emits
选项带有名称由$emit()
触发
- ⚙️ 此规则包含在
"plugin:vue/strongly-recommended"
、*.configs["flat/strongly-recommended"]
、"plugin:vue/recommended"
和*.configs["flat/recommended"]
中。
💡此规则报告的某些问题可以通过编辑器 suggestions 手动修复。
¥💡 Some problems reported by this rule are manually fixable by editor suggestions.
📖 规则详情
此规则报告未使用 emits
选项声明的事件触发器。(emits
选项是 Vue.js 3.0.0+ 中的新增选项)
¥This rule reports event triggers not declared with the emits
option. (The emits
option is a new in Vue.js 3.0.0+)
显式 emits
声明用作自文档代码。这对于其他开发者很有用,可以让他们立即了解组件应该触发什么事件。此外,随着 Vue.js 3.0.0+ 中属性 fallthrough 的变化,组件上的 v-on
监听器将默认作为原生监听器 fallthrough。在 emits
中将其声明为仅限组件的事件,以避免不必要地注册原生监听器。
¥Explicit emits
declaration serves as self-documenting code. This can be useful for other developers to instantly understand what events the component is supposed to emit. Also, with attribute fallthrough changes in Vue.js 3.0.0+, v-on
listeners on components will fallthrough as native listeners by default. Declare it as a component-only event in emits
to avoid unnecessary registration of native listeners.
🔧选项
¥🔧 Options
json
{
"vue/require-explicit-emits": ["error", {
"allowProps": false
}]
}
"allowProps"
...如果是true
,则允许在props
中定义的事件名称。默认false
¥
"allowProps"
... Iftrue
, allow event names defined inprops
. defaultfalse
"allowProps": true
👫相关规则
¥👫 Related Rules
📚扩展阅读
¥📚 Further Reading
🚀版本
¥🚀 Version
此规则在 eslint-plugin-vue v7.0.0 中引入
¥This rule was introduced in eslint-plugin-vue v7.0.0
🔍代码实现
¥🔍 Implementation