vue/no-array-index-key
Disallow using the v-for index variable directly as the :key
Default severity: warning
Presets: nuxt, opinionated
Automatic fix: None; review the suggested change
Applies to: Vue SFC templates and blocks, with script context where the rule requires it
Options: No rule-specific options. Severity and preset selection are configurable.
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({
lint: {
vize: {
"preset": "incremental",
"rules": {
"vue/no-array-index-key": "warn"
}
},
},
});
vp run lint
Bad
The list key is its current index, so item identity changes when the list is reordered.
<template>
<li v-for="(item, index) in items" :key="index">{{ item.name }}</li>
</template>
Good
The key comes from item.id, preserving the identity of each item across position changes.
<template>
<li v-for="item in items" :key="item.id">{{ item.name }}</li>
</template>
Good avoids this rule's finding under the configuration above; other rules may still report diagnostics.