# vue/custom-event-name-casing
enforce specific casing for custom event name
Define a style for custom event name casing for consistency purposes.
# π Rule Details
This rule aims to warn the custom event names other than the configured casing.
Vue 2 recommends using kebab-case for custom event names.
Event names will never be used as variable or property names in JavaScript, so thereβs no reason to use camelCase or PascalCase. Additionally,
v-on
event listeners inside DOM templates will be automatically transformed to lowercase (due to HTMLβs case-insensitivity), sov-on:myEvent
would becomev-on:myevent
β makingmyEvent
impossible to listen to.For these reasons, we recommend you always use kebab-case for event names.
See Guide (for v2) - Custom Events (opens new window) for more details.
In Vue 3, using either camelCase or kebab-case for your custom event name does not limit its use in v-on. However, following JavaScript conventions, camelCase is more natural.
See Guide - Custom Events (opens new window) for more details.
This rule enforces kebab-case by default.
<template>
<!-- β GOOD -->
<button @click="$emit('my-event')" />
<!-- β BAD -->
<button @click="$emit('myEvent')" />
</template>
<script>
export default {
methods: {
onClick () {
/* β GOOD */
this.$emit('my-event')
this.$emit('update:myProp', myProp)
/* β BAD */
this.$emit('myEvent')
}
}
}
</script>
# π§ Options
{
"vue/custom-event-name-casing": ["error",
"kebab-case" | "camelCase",
{
"ignores": []
}
]
}
"kebab-case"
(default) ... Enforce custom event names to kebab-case."camelCase"
... Enforce custom event names to camelCase.ignores
(string[]
) ... The event names to ignore. Sets the event name to allow. For example, custom event names, Vue components event with special name, or Vue library component event name. You can set the regexp by writing it like"/^name/"
orclick:row
orfooBar
.
# "kebab-case"
<template>
<!-- β GOOD -->
<button @click="$emit('my-event')" />
<!-- β BAD -->
<button @click="$emit('myEvent')" />
</template>
<script>
export default {
methods: {
onClick () {
/* β GOOD */
this.$emit('my-event')
/* β BAD */
this.$emit('myEvent')
}
}
}
</script>
# "camelCase"
<template>
<!-- β GOOD -->
<button @click="$emit('myEvent')" />
<!-- β BAD -->
<button @click="$emit('my-event')" />
</template>
<script>
export default {
methods: {
onClick () {
/* β GOOD */
this.$emit('myEvent')
/* β BAD */
this.$emit('my-event')
}
}
}
</script>
# "ignores": ["fooBar", "/^[a-z]+(?:-[a-z]+)*:[a-z]+(?:-[a-z]+)*$/u"]
<template>
<!-- β GOOD -->
<button @click="$emit('click:row')" />
<button @click="$emit('fooBar')" />
<!-- β BAD -->
<button @click="$emit('myEvent')" />
</template>
<script>
export default {
methods: {
onClick () {
/* β GOOD */
this.$emit('click:row')
this.$emit('fooBar')
/* β BAD */
this.$emit('myEvent')
}
}
}
</script>
# π Further Reading
# π« Related Rules
# π Version
This rule was introduced in eslint-plugin-vue v7.0.0