vue/no-use-v-if-with-v-for
disallow using
v-ifon the same element asv-for
- ⚙️ This rule is included in all of
"plugin:vue/essential",*.configs["flat/essential"],"plugin:vue/vue2-essential",*.configs["flat/vue2-essential"],"plugin:vue/strongly-recommended",*.configs["flat/strongly-recommended"],"plugin:vue/vue2-strongly-recommended",*.configs["flat/vue2-strongly-recommended"],"plugin:vue/recommended",*.configs["flat/recommended"],"plugin:vue/vue2-recommended"and*.configs["flat/vue2-recommended"].
📖 Rule Details
This rule is aimed at preventing the use of v-for directives together with v-if directives on the same element.
There are two common cases where this can be tempting:
- To filter items in a list (e.g.
v-for="user in users" v-if="user.isActive"). In these cases, replaceuserswith a new computed property that returns your filtered list (e.g.activeUsers). - To avoid rendering a list if it should be hidden (e.g.
v-for="user in users" v-if="shouldShowUsers"). In these cases, move thev-ifto a container element (e.g.ul,ol).
🔧 Options
json
{
"vue/no-use-v-if-with-v-for": ["error", {
"allowUsingIterationVar": false
}]
}allowUsingIterationVar(boolean) ... Enables Thev-ifdirective use the reference which is to the variables which are defined by thev-fordirectives. Default isfalse.
"allowUsingIterationVar": true
👫 Related Rules
📚 Further Reading
- Style guide - Avoid v-if with v-for
- Guide - Conditional Rendering / v-if with v-for
- Guide - List Rendering / v-for with v-if
🚀 Version
This rule was introduced in eslint-plugin-vue v4.6.0