diff --git a/lib/rules/valid-v-for.js b/lib/rules/valid-v-for.js
index 47d8f5029..91a36e17d 100644
--- a/lib/rules/valid-v-for.js
+++ b/lib/rules/valid-v-for.js
@@ -41,17 +41,22 @@ function isUsingIterationVar (vFor, vBindKey) {
* @param {RuleContext} context The rule context to report.
* @param {ASTNode} vFor The attribute node of `v-for` to check.
* @param {ASTNode} element The element node to check.
+ * @param {boolean} child Are we working on child element.
*/
-function checkKey (context, vFor, element) {
+function checkKey (context, vFor, element, child) {
if (element.name === 'template') {
for (const child of element.children) {
if (child.type === 'VElement') {
- checkKey(context, vFor, child)
+ checkKey(context, vFor, child, true)
}
}
return
}
+ if (child && utils.hasDirective(element, 'for')) { // template(v-for) > div(v-for)
+ return
+ }
+
const vBindKey = utils.getDirective(element, 'bind', 'key')
if (utils.isCustomComponent(element) && vBindKey == null) {
@@ -83,7 +88,7 @@ function create (context) {
"VAttribute[directive=true][key.name='for']" (node) {
const element = node.parent.parent
- checkKey(context, node, element)
+ checkKey(context, node, element, false)
if (node.key.argument) {
context.report({
diff --git a/tests/lib/rules/valid-v-for.js b/tests/lib/rules/valid-v-for.js
index e3da7c5ed..04ee73cbe 100644
--- a/tests/lib/rules/valid-v-for.js
+++ b/tests/lib/rules/valid-v-for.js
@@ -82,6 +82,10 @@ tester.run('valid-v-for', rule, {
{
filename: 'test.vue',
code: 'foo'
+ },
+ {
+ filename: 'test.vue',
+ code: ''
}
],
invalid: [