vue/no-use-v-if-with-v-for
Disallow using v-if on the same element as v-for.
| Default severity | Presets | Automatic fix | Options |
|---|---|---|---|
warning |
essential, happy-path, nuxt, ecosystem, opinionated |
No | Rule options |
Applies to: Vue SFC templates and blocks, with script context where the rule requires it.
Bad
The same list element combines v-if and v-for, but the condition does not reference the loop binding.
<template>
<li v-for="item in items" v-if="showAll" :key="item.id">
{{ item.name }}
</li>
</template>
Good
With allowUsingIterationVar enabled, the condition references item from the same v-for.
<template>
<li v-for="item in items" v-if="item.visible" :key="item.id">
{{ item.name }}
</li>
</template>
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"vue/no-use-v-if-with-v-for": "warn"
},
"ruleOptions": {
"vue/no-use-v-if-with-v-for": {
"allowUsingIterationVar": true
}
}
},
});
Then run vp run lint.