Skip to content

no-v-for-template-key-on-child

Reports a :key on a child of a <template v-for>.

In Vue 3 the key belongs on the <template v-for>; a key on a child is not used, so the list is patched in place and state stays on the wrong element.

To fix, move the :key to the <template>.

Reported
...
<component :is="view" />
<template v-for="x in xs"><li :key="x" /></template>
...
<MyCard v-for="x in xs" />
...
angular:
lint:
rules:
no-v-for-template-key-on-child: warn # off, warn (default), error
html:
lint:
rules:
no-v-for-template-key-on-child: warn # off, warn (default), error
svelte:
lint:
rules:
no-v-for-template-key-on-child: warn # off, warn (default), error
vue:
lint:
rules:
no-v-for-template-key-on-child: warn # off, warn (default), error

Enabled by the presets: html/eslint-plugin-vue-recommended.

Suppress one line with sudsy-disable-next-line no-v-for-template-key-on-child in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
eslint-plugin-vue no-v-for-template-key-on-child full