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