Skip to content

useVueVModel (HTML)

Language HTML
biome.json
{
"linter": {
"rules": {
"nursery": {
"useVueVModel": "error"
}
}
}
}

Enforce v-model instead of a prop binding paired with an update: listener that writes the value back.

A component that supports v-model receives a prop, and emits an update: event with the new value when it changes. Binding the prop and writing the new value back by hand, as in :title="title" @update:title="title = $event", does the same thing as v-model:title="title". The v-model form is shorter, and the prop and its listener can’t get out of sync.

For the modelValue prop, the rule suggests the shorter v-model="value" form.

The rule only checks components. It reports a pair when the listener does nothing but assign the new value to the bound expression, written either as value = $event or as (newValue) => value = newValue. Bindings and listeners with modifiers are ignored.

<template>
<MyComponent :modelValue="text" @update:modelValue="text = $event" />
</template>
<template>
<MyComponent :title="title" @update:title="title = $event" />
</template>
<template>
<MyComponent v-bind:title="title" v-on:update:title="(value) => title = value" />
</template>
<template>
<MyComponent v-model="text" />
<MyComponent v-model:title="title" />
<MyComponent :title="title" @update:title="otherTitle = $event" />
<MyComponent :title="title" @update:title="setTitle($event)" />
<MyComponent :title="title" @update:title="title = $event; save()" />
</template>