Skip to content

noVueVForTemplateKeyOnChild (HTML)

Language HTML
biome.json
{
"linter": {
"rules": {
"nursery": {
"noVueVForTemplateKeyOnChild": "error"
}
}
}
}

Disallow placing the key of a <template v-for> on its child elements.

When a <template> tag repeats its content with v-for, Vue expects the key on the <template> tag itself. A key on a child element that uses the loop variables belongs on the <template> tag instead.

Child elements that have their own v-if, v-else-if, v-else, or v-for are not reported, and neither are keys that don’t use any variable from the <template>’s v-for.

<template>
<template v-for="todo in todos">
<TodoItem :key="todo.id" />
</template>
</template>
<template>
<template v-for="todo in todos" :key="todo.id">
<TodoItem />
</template>
<template v-for="todo in todos" :key="todo.id">
<TodoItem v-if="todo.visible" :key="todo.id" />
</template>
</template>