JS.VUE.NO.V.FOR.TEMPLATE.KEY

Disallow 'key' attribute on '<template v-for>'

Rule Details

This rule reports the <template v-for> elements which have key attribute.

In Vue.js 2.x, disallows key attribute on <template> elements.

This rule is targeted at Vue.js 2.x. If you are using Vue.js 3.x, enable the no-v-for-template-key-on-child rule instead. Don't enable both rules together; they are conflicting.

{'vue/no-v-for-template-key': ['error']}

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

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

If you want to report keys placed on <template> without v-for, use the no-template-key rule.

Options

Nothing.

Further Reading

  • API - Special Attributes - key (https://v3.vuejs.org/api/special-attributes.html#key)
  • API (for v2) - Special Attributes - key (https://v2.vuejs.org/v2/api/#key)

The content on this page is adapted from the ESLint User Guide. Copyright © OpenJS Foundation and other contributors, www.openjsf.org. All rights reserved. https://eslint.org/docs/rules/