--- pageClass: rule-details sidebarDepth: 0 title: vue/valid-v-for description: enforce valid `v-for` directives since: v3.11.0 --- # vue/valid-v-for > enforce valid `v-for` directives - :gear: 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"` This rule checks whether every `v-for` directive is valid. ## :book: Rule Details This rule reports `v-for` directives in the following cases: - The directive has that argument. E.g. `
` - The directive has that modifier. E.g. `
` - The directive does not have that attribute value. E.g. `
` - If the element which has the directive is a custom component, the component does not have `v-bind:key` directive. E.g. `` - The `v-bind:key` directive does not use the variables which are defined by the `v-for` directive. E.g. `
` If the element which has the directive is a reserved element, this rule does not report it even if the element does not have `v-bind:key` directive because it's not fatal error. [vue/require-v-for-key] rule reports it. ```vue ``` ::: warning Note This rule does not check syntax errors in directives. [vue/no-parsing-error] rule reports it. The following cases are syntax errors: - The directive's value isn't `alias in expr`. E.g. `
` - The alias isn't LHS. E.g. `
` ::: ## :wrench: Options ```json { "vue/valid-v-for": [ "error", { "allowEmptyAlias": false } ] } ``` - `allowEmptyAlias` (`boolean`) ... Allows empty aliases in `v-for` expressions. Default is `false`. ### `"allowEmptyAlias": false` (default) ```vue ``` ### `"allowEmptyAlias": true` ```vue ``` ## :couple: Related Rules - [vue/require-v-for-key] - [vue/no-parsing-error] [vue/require-v-for-key]: ./require-v-for-key.md [vue/no-parsing-error]: ./no-parsing-error.md ## :rocket: Version This rule was introduced in eslint-plugin-vue v3.11.0 ## :mag: Implementation - [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/valid-v-for.js) - [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/valid-v-for.test.ts)