vue/prefer-v-model
Prefere v-model a um bind e listener update equivalentes.
| Severidade padrão | Predefinições | Correção automática | Opções |
|---|---|---|---|
warning |
Nenhuma | Não | Nenhuma |
Aplicável a: Templates e blocos de SFC Vue, com o contexto do script quando exigido pela regra.
Incorreto
O bind e o listener sincronizam manualmente o mesmo valor.
<template>
<TextField :model-value="value" @update:model-value="value = $event" />
</template>
Correto
v-model expressa uma vez o mesmo contrato bidirecional.
<template>
<TextField v-model="value" />
</template>
Configuração (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"vue/prefer-v-model": "warn"
}
},
});
Depois, execute vp run lint.