vue/use-v-on-exact
Enforce .exact modifier on v-on when there are modifier-based handlers.
| Default severity | Presets | Automatic fix | Options |
|---|---|---|---|
warning |
essential, happy-path, nuxt, ecosystem, opinionated |
No | None |
Applies to: Vue SFC templates and blocks, with script context where the rule requires it.
When handlers overlap
The rule compares listeners for the same event on a native element. It ignores custom component events unless both listeners use .native. Different event names and disjoint keyboard filters do not conflict.
System modifiers are required keys, so @keydown.alt.shift also accepts Ctrl+Alt+Shift. If a second handler uses @keydown.alt.ctrl.shift, add .exact to the broader handler to keep those actions separate. .exact permits its declared system modifiers and rejects additional Ctrl, Shift, Alt or Meta keys.
Multiple keyboard modifiers are alternatives: @keydown.up.down accepts either arrow key. It can overlap @keydown.ctrl.down on Ctrl+ArrowDown. The rule reports the directive key that needs .exact, excluding its handler expression.
Bad
The plain click handler can also run on Ctrl-click, overlapping the separate .ctrl handler.
<template>
<button type="button" @click="handleClick" @click.ctrl="handleCtrlClick">
Save
</button>
</template>
Good
.exact limits the ordinary click handler to clicks without modifier keys; the Ctrl-specific handler remains separate.
<template>
<button
type="button"
@click.exact="handleClick"
@click.ctrl="handleCtrlClick"
>
Save
</button>
</template>
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"vue/use-v-on-exact": "warn"
}
},
});
Then run vp run lint.