pageClass | sidebarDepth | title | description | since |
---|---|---|---|---|
rule-details |
0 |
vue/v-on-event-hyphenation |
enforce v-on event naming style on custom components in template |
v7.4.0 |
enforce v-on event naming style on custom components in template
- ⚙️ This rule is included in all of
"plugin:vue/vue3-strongly-recommended"
,*.configs["flat/strongly-recommended"]
,"plugin:vue/vue3-recommended"
and*.configs["flat/recommended"]
. - 🔧 The
--fix
option on the command line can automatically fix some of the problems reported by this rule.
This rule enforces using hyphenated v-on event names on custom components in Vue templates.
<template>
<!-- ✓ GOOD -->
<MyComponent v-on:custom-event="handleEvent" />
<MyComponent @custom-event="handleEvent" />
<!-- ✗ BAD -->
<MyComponent v-on:customEvent="handleEvent" />
<MyComponent @customEvent="handleEvent" />
</template>
{
"vue/v-on-event-hyphenation": ["error", "always" | "never", {
"autofix": false,
"ignore": [],
"ignoreTags": []
}]
}
"always"
(default) ... Use hyphenated event name."never"
... Don't use hyphenated event name."ignore"
... Array of event names that don't need to follow the specified casing."ignoreTags"
... Array of tag names whose events don't need to follow the specified casing."autofix"
... Iftrue
, enable autofix. If you are using Vue 2, we recommend that you do not use it due to its side effects.
It errors on upper case letters.
<template>
<!-- ✓ GOOD -->
<MyComponent v-on:custom-event="handleEvent" />
<!-- ✗ BAD -->
<MyComponent v-on:customEvent="handleEvent" />
</template>
It errors on hyphens.
<template>
<!-- ✓ GOOD -->
<MyComponent v-on:customEvent="handleEvent" />
<!-- ✗ BAD -->
<MyComponent v-on:custom-event="handleEvent" />
</template>
Don't use hyphenated name but allow custom event names
<template>
<!-- ✓ GOOD -->
<MyComponent v-on:custom-event="handleEvent" />
<MyComponent v-on:myEvent="handleEvent" />
<!-- ✗ BAD -->
<MyComponent v-on:my-event="handleEvent" />
</template>
<template>
<!-- ✓ GOOD -->
<custom-component v-on:my-event="handleEvent" />
<!-- ✗ BAD -->
<my-component v-on:my-event="handleEvent" />
</template>
This rule was introduced in eslint-plugin-vue v7.4.0