Skip to content

vue/no-use-v-if-with-v-for

disallow using v-if on the same element as v-for

  • ⚙️ This rule is included in the following preset configs:
    • *.configs["flat/essential"]
    • *.configs["flat/vue2-essential"]
    • *.configs["flat/strongly-recommended"]
    • *.configs["flat/vue2-strongly-recommended"]
    • *.configs["flat/recommended"]
    • *.configs["flat/vue2-recommended"]
    • "plugin:vue/essential"
    • "plugin:vue/vue2-essential"
    • "plugin:vue/strongly-recommended"
    • "plugin:vue/vue2-strongly-recommended"
    • "plugin:vue/recommended"
    • "plugin:vue/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, replace users with 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 the v-if to a container element (e.g. ul, ol).
Now loading...

🔧 Options

json
{
  "vue/no-use-v-if-with-v-for": ["error", {
    "allowUsingIterationVar": false
  }]
}
  • allowUsingIterationVar (boolean) ... Enables The v-if directive use the reference which is to the variables which are defined by the v-for directives. Default is false.

"allowUsingIterationVar": true

Now loading...

📚 Further Reading

🚀 Version

This rule was introduced in eslint-plugin-vue v4.6.0

🔍 Implementation