Vize

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

template v-for の key を子ではなく template に指定します。

悪い例 · 良い例

既定の重大度: error
プリセット: essential, happy-path, nuxt, ecosystem, opinionated
自動修正: なし。修正内容を確認してください
適用範囲: Vue SFC のテンプレート・ブロック。必要な script の文脈も例に含めています。
オプション: ルール固有のオプションはありません。重大度とプリセットは設定できます。

設定(Vite+)

import { defineConfig } from "@vizejs/vite-plugin/vite-plus";

export default defineConfig({
  lint: {
    vize: {
      "preset": "incremental",
      "rules": {
        "vue/no-v-for-template-key-on-child": "error"
      }
    },
  },
});
vp run lint

悪い

繰り返す template に key がなく、子の p に指定しています。

<template>
<template v-for="item in items"><p :key="item.id">{{ item.name }}</p></template>
</template>

良い

template の v-for に key を移し、繰り返す fragment 全体を識別します。

<template>
<template v-for="item in items" :key="item.id"><p>{{ item.name }}</p></template>
</template>

良い例は上記の設定でこのルールの検出を避ける例です。他のルールでは検出される場合があります。

実装 · 全ルール