Skip to content

noVueTemplateKey (HTML)

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

Disallow the key attribute on <template> elements in Vue.

A <template> element groups other elements without adding anything to the page. Vue uses key to tell elements apart when it updates the page, but a <template> isn’t an element on the page, so a key written on it does nothing. Put the key on the elements inside the <template> instead.

A key on a <template> that also has v-for is allowed, because Vue uses that key to keep track of each item in the list.

<template>
<template key="foo"><div /></template>
</template>
code-block.vue:2:13 lint/nursery/noVueTemplateKey ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ The key attribute isn't allowed on a <template> element.

1 │ <template>
> 2 │ <template key="foo"><div /></template>
│ ^^^^^^^^^
3 │ </template>
4 │

ℹ A <template> isn't an element on the page, so Vue can't use its key to tell it apart from other elements.

ℹ Put the key on the elements inside the <template> instead.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

<template>
<template :key="item.id"><div /></template>
</template>
code-block.vue:2:13 lint/nursery/noVueTemplateKey ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ The key attribute isn't allowed on a <template> element.

1 │ <template>
> 2 │ <template :key="item.id"><div /></template>
│ ^^^^^^^^^^^^^^
3 │ </template>
4 │

ℹ A <template> isn't an element on the page, so Vue can't use its key to tell it apart from other elements.

ℹ Put the key on the elements inside the <template> instead.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

<template>
<div key="foo"></div>
<template v-for="item in list" :key="item.id"><div /></template>
</template>