Przeglądaj źródła

key nested children by default (fix #3611)

Evan You 9 lat temu
rodzic
commit
63e4757fbd

+ 7 - 2
src/core/vdom/helpers.js

@@ -5,7 +5,8 @@ import VNode from './vnode'
 
 export function normalizeChildren (
   children: any,
-  ns: string | void
+  ns: string | void,
+  nestedIndex: number | void
 ): Array<VNode> | void {
   if (isPrimitive(children)) {
     return [createTextVNode(children)]
@@ -17,7 +18,7 @@ export function normalizeChildren (
       const last = res[res.length - 1]
       //  nested
       if (Array.isArray(c)) {
-        res.push.apply(res, normalizeChildren(c, ns))
+        res.push.apply(res, normalizeChildren(c, ns, i))
       } else if (isPrimitive(c)) {
         if (last && last.text) {
           last.text += String(c)
@@ -33,6 +34,10 @@ export function normalizeChildren (
           if (ns) {
             applyNS(c, ns)
           }
+          // default key for nested array children (likely generated by v-for)
+          if (c.key == null && nestedIndex != null) {
+            c.key = `__vlist_${nestedIndex}_${i}__`
+          }
           res.push(c)
         }
       }

+ 1 - 1
src/platforms/web/runtime/components/transition-group.js

@@ -42,7 +42,7 @@ export default {
     for (let i = 0; i < rawChildren.length; i++) {
       const c = rawChildren[i]
       if (c.tag) {
-        if (c.key != null) {
+        if (c.key != null && String(c.key).indexOf('__vlist') !== 0) {
           children.push(c)
           map[c.key] = c
           ;(c.data || (c.data = {})).transition = transitionData