vue/valid-v-model
Enforce valid v-model directives.
| Default severity | Presets | Automatic fix | Options |
|---|---|---|---|
error |
essential, happy-path, nuxt, ecosystem, opinionated |
No | None |
Applies to: Vue SFC templates and blocks, with script context where the rule requires it.
Bad
A native <div> cannot use v-model as a form control, and a bare input directive has no writable target expression.
<template>
<div v-model="value"></div>
<input v-model />
</template>
Good
Bind the input, select, textarea, or custom component to the shown writable variables.
<template>
<input v-model="value" />
<select v-model="selected"></select>
<textarea v-model="text"></textarea>
<MyInput v-model="value" />
</template>
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"vue/valid-v-model": "error"
}
},
});
Then run vp run lint.