vue/require-v-for-key
Require v-bind:key with v-for 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
Each repeated <li> lacks a key that identifies its corresponding item during list updates.
<template>
<li v-for="item in items">{{ item.name }}</li>
</template>
Good
:key="item.id" gives each repeated node the item's identity rather than its current position.
<template>
<li v-for="item in items" :key="item.id">{{ item.name }}</li>
</template>
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"vue/require-v-for-key": "error"
}
},
});
Then run vp run lint.