The first variable of v-for
should not be used as an index of the iterated array
- VUE_MISUSED_V_FOR_VAR
- Error
- Medium
- vue
This rule applies when the first variable of a v-for
directive is used as an index of the iterated array (or a key if used on a plain object).
Since the first variable already holds the current element of the array, using it as an index of the array is likely a programmer's mistake. One should use just the variable itself.
If the array index is actually needed, the second variable should be used which holds the current index.
Noncompliant Code Example
View with compliant examples side by side<template>
<div>
<div v-for="i in items">
{{ items[i] /* VUE_MISUSED_V_FOR_VAR alarm */ }}
</div>
</div>
</template>
Compliant Code Example
View with noncompliant examples side by side<template>
<div>
<div v-for="item in items">
{{ item }}
</div>
</div>
</template>
Version
This rule was introduced in DeepScan 1.40.0.