Skip to content

v-for-key

Reports a v-for with no :key (or v-bind:key). On a <template> or <slot> the key goes on the child elements; components are left to valid-v-for.

Without a key Vue patches the elements in place when the list changes, which keeps stale state in inputs and components and breaks transitions.

To fix, add a :key with a value that is unique to each item.

Reported
<ul>
<li v-for="x in xs">a</li>
<li v-for="x in xs" :key="x.id">b</li>
<li v-for="x in xs" v-bind:key="x">c</li>
</ul>
angular:
lint:
rules:
v-for-key: warn # off, warn (default), error
html:
lint:
rules:
v-for-key: warn # off, warn (default), error
svelte:
lint:
rules:
v-for-key: warn # off, warn (default), error
vue:
lint:
rules:
v-for-key: warn # off, warn (default), error

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

Suppress one line with sudsy-disable-next-line v-for-key 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 require-v-for-key full