vue/v-on-handler-style
Enforce writing v-on handlers as method references.
| Default severity | Presets | Automatic fix | Options |
|---|---|---|---|
warning |
nuxt, opinionated |
No | Rule options |
Applies to: Vue SFC templates and blocks, with script context where the rule requires it.
Bad
The handlers use inline functions, mutations, or multiple statements instead of reusable method references.
<template>
<button @click="count++"></button>
<button @click="doThis(); doThat()"></button>
<button @click="foo = bar"></button>
</template>
Good
Use a handler reference. Move inline logic into a named method so the template keeps a stable, reusable handler.
<template>
<button @click="handler"></button>
<button @click="foo.bar"></button>
</template>
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"vue/v-on-handler-style": "warn"
}
},
});
Then run vp run lint.