Skip to content

no-use-v-if-with-v-for

Reports an element that has v-if and v-for together.

In Vue 3 v-if is evaluated first, so a condition on the loop variable fails with an error, and in Vue 2 the order was the other way round, which makes the code unsafe to port.

To fix, filter the list in a computed value, or move the v-if to a wrapping <template>.

Reported
<ul>
<li v-for="x in xs" v-if="x.on" :key="x.id">a</li>
<li v-if="a">b</li>
<template v-for="x in xs" :key="x.id"><li v-if="x.on">c</li></template>
</ul>
angular:
lint:
rules:
no-use-v-if-with-v-for: warn # off, warn (default), error
html:
lint:
rules:
no-use-v-if-with-v-for: warn # off, warn (default), error
svelte:
lint:
rules:
no-use-v-if-with-v-for: warn # off, warn (default), error
vue:
lint:
rules:
no-use-v-if-with-v-for: warn # off, warn (default), error

Enabled by the presets: html/eslint-plugin-vue-recommended.

Suppress one line with sudsy-disable-next-line no-use-v-if-with-v-for in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
eslint-plugin-vue no-use-v-if-with-v-for full