vue/valid-v-for
v-for の式と変数宣言を検査します。
既定の重大度: 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/valid-v-for": "error"
}
},
},
});
vp run lint
悪い
繰り返し式がないか、対応していない .stop 修飾子を付けています。
<template>
<div v-for></div>
<div v-for=""></div>
<div v-for.stop="item in items"></div>
</template>
良い
item in items や (item, index) of items の完全な式と、例の key を使います。
<template>
<div v-for="item in items" :key="item.id"></div>
<div v-for="(item, index) of items" :key="index"></div>
</template>
良い例は上記の設定でこのルールの検出を避ける例です。他のルールでは検出される場合があります。