vue/v-on-handler-style
Enforce writing v-on handlers as a method reference or an inline function
Default severity: warning
Presets: nuxt, opinionated
Automatic fix: None; review the suggested change
Applies to: Vue SFC templates and blocks, with script context where the rule requires it
Options: No rule-specific options. Severity and preset selection are configurable.
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({
lint: {
vize: {
"preset": "incremental",
"rules": {
"vue/v-on-handler-style": "warn"
}
},
},
});
vp run lint
Bad
The handlers put mutations and multiple statements directly in the event attribute.
<template>
<button @click="count++"></button>
<button @click="doThis(); doThat()"></button>
<button @click="foo = bar"></button>
</template>
Good
Use a handler reference, or an arrow/function expression when inline logic is needed. The function boundary makes the handler form explicit.
<template>
<button @click="handler"></button>
<button @click="foo.bar"></button>
<button @click="() => count++"></button>
<button @click="function () { count++ }"></button>
</template>
Good avoids this rule's finding under the configuration above; other rules may still report diagnostics.