Vue · Template
vite-doctor/vuetemplatewarnNo fix
Why it happens
Vue reuses DOM nodes and component instances by key. With an index key, inserting, removing or reordering items keeps each instance at its position, so component state, input values and transitions attach to a different item.
Fix
Key each item by a stable, unique field of the item itself, such as its id.
Example
Key a component list by item id
Before
<script setup lang="ts">
import TodoRow from "./TodoRow.vue"; // keeps a draft in ref()
</script>
<template>
<TodoRow v-for="(todo, index) in todos" :key="index" :todo="todo" />
</template>
After
<script setup lang="ts">
import TodoRow from "./TodoRow.vue"; // keeps a draft in ref()
</script>
<template>
<TodoRow v-for="todo in todos" :key="todo.id" :todo="todo" />
</template>
Verify the fix
Run only this rule after editing so the report stays focused on the diagnostic you are closing:
pnpm vite-doctor . --framework vue --rules vue/template/no-index-key-on-stateful-list