Vue · Template

VUE0045Key v-for items that hold state

Reports v-for elements without a key when an item holds state: a component whose source keeps local state, an element with v-model, a native form control, or a child of <TransitionGroup>. Unkeyed lists of stateless elements are not reported.

Why it happens

Without a key, Vue patches a v-for list in place. When items are inserted, removed or reordered, each component instance and form control stays at its position, so local state, typed input and focus end up on a different item, and <TransitionGroup> does not animate unkeyed children at all.

Fix

Bind to a stable, unique field of the item, such as its id. Lists of plain elements without state can stay unkeyed.

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 in todos" :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/require-v-for-key
Copyright © 2026