noVueVForTemplateKeyOnChild (HTML)
Language HTML
Summary
Section titled “Summary”- Rule available since:
v2.6.5 - Diagnostic Category:
lint/nursery/noVueVForTemplateKeyOnChild - This rule doesn’t have a fix.
- The default severity of this rule is error.
- This rule belongs to the following domains:
- Sources:
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noVueVForTemplateKeyOnChild": "error" } } }}Description
Section titled “Description”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.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”<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>Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.