useVueVModel (HTML)
Summary
Section titled “Summary”- Rule available since:
v2.6.4 - Diagnostic Category:
lint/nursery/useVueVModel - This rule has an unsafe fix.
- The default severity of this rule is warning.
- This rule belongs to the following domains:
- Sources:
- Same as
vue/prefer-v-model
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "useVueVModel": "error" } } }}Description
Section titled “Description”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.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”<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>Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.