Skip to content

no-use-v-else-with-v-for

Reports an element that has v-else and v-for together. Only in .vue files.

v-else is evaluated first and cannot read the loop variable, and the result is not what the markup reads like.

To fix, put the v-for on a child or on a wrapping <template>.

Reported
...
<MyCard v-for="x in xs" />
...
<li v-else v-for="x in xs" :key="x" />
<template v-for="x in xs" :key="x"><li /></template>
...
angular:
lint:
rules:
no-use-v-else-with-v-for: warn # off, warn (default), error
html:
lint:
rules:
no-use-v-else-with-v-for: warn # off, warn (default), error
svelte:
lint:
rules:
no-use-v-else-with-v-for: warn # off, warn (default), error
vue:
lint:
rules:
no-use-v-else-with-v-for: warn # off, warn (default), error

Suppress one line with sudsy-disable-next-line no-use-v-else-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-else-with-v-for full