vue/no-use-v-if-with-v-for
Disallow using v-if on the same element as v-for
Default severity: warning
Presets: essential, happy-path, nuxt, ecosystem, opinionated
Automatic fix: None; review the suggested change
Applies to: Vue SFC templates and blocks, with script context where the rule requires it
Options: No rule-specific options. Severity and preset selection are configurable.
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({
lint: {
vize: {
"preset": "incremental",
"rules": {
"vue/no-use-v-if-with-v-for": "warn"
}
},
},
});
vp run lint
Bad
The same list element combines v-if and v-for and tests visibility through the loop binding.
<template>
<li v-for="item in items" v-if="item.visible" :key="item.id">
{{ item.name }}
</li>
</template>
Good
A computed collection filters the visible items before the template iterates over them.
<script setup lang="ts">
const visibleItems = computed(() => items.filter((item) => item.visible));
</script>
<template>
<li v-for="item in visibleItems" :key="item.id">
{{ item.name }}
</li>
</template>
Good avoids this rule's finding under the configuration above; other rules may still report diagnostics.