Skip to content

vue/valid-v-for

强制有效的 v-for 指令

  • ⚙️ 此规则包含在 "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"*.configs["flat/vue2-recommended"] 中。

此规则检查每个 v-for 指令是否有效。

¥This rule checks whether every v-for directive is valid.

📖 规则详情

此规则在以下情况下报告 v-for 指令:

¥This rule reports v-for directives in the following cases:

  • 该指令有该参数。例如<div v-for:aaa></div>

    ¥The directive has that argument. E.g. <div v-for:aaa></div>

  • 该指令具有该修饰符。例如<div v-for.bbb></div>

    ¥The directive has that modifier. E.g. <div v-for.bbb></div>

  • 该指令没有该属性值。例如<div v-for></div>

    ¥The directive does not have that attribute value. E.g. <div v-for></div>

  • 如果具有该指令的元素是自定义组件,则该组件没有 v-bind:key 指令。例如<your-component v-for="item in list"></your-component>

    ¥If the element which has the directive is a custom component, the component does not have v-bind:key directive. E.g. <your-component v-for="item in list"></your-component>

  • v-bind:key 指令不使用 v-for 指令定义的变量。例如<div v-for="x in list" :key="foo"></div>

    ¥The v-bind:key directive does not use the variables which are defined by the v-for directive. E.g. <div v-for="x in list" :key="foo"></div>

如果具有该指令的元素是保留元素,即使该元素没有 v-bind:key 指令,此规则也不会报告它,因为这不是致命错误。vue/require-v-for-key 规则报告它。

¥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.

Now loading...

注意

此规则不检查指令中的语法错误。vue/no-parsing-error 规则报告它。以下情况是语法错误:

¥This rule does not check syntax errors in directives. vue/no-parsing-error rule reports it. The following cases are syntax errors:

  • 该指令的值不是 alias in expr。例如<div v-for="foo"></div>

    ¥The directive's value isn't alias in expr. E.g. <div v-for="foo"></div>

  • 别名不是 LHS。例如<div v-for="foo() in list"></div>

    ¥The alias isn't LHS. E.g. <div v-for="foo() in list"></div>

🔧选项

¥🔧 Options

无。

¥Nothing.

👫相关规则

¥👫 Related Rules

🚀版本

¥🚀 Version

此规则在 eslint-plugin-vue v3.11.0 中引入

¥This rule was introduced in eslint-plugin-vue v3.11.0

🔍代码实现

¥🔍 Implementation

eslint-plugin-vue v10.0 中文网 - 粤ICP备13048890号