Selaa lähdekoodia

fix children flattening

Evan You 10 vuotta sitten
vanhempi
commit
e9ae8187c2

+ 2 - 1
src/compiler/codegen/index.js

@@ -3,6 +3,7 @@ import { genDirectives } from './directives/index'
 
 export function generate (ast) {
   const code = ast ? genElement(ast) : '__h__("div")'
+  console.log(code)
   return `with (this) { return ${code}}`
 }
 
@@ -32,7 +33,7 @@ function genFor (el) {
   const exp = el.for
   const alias = el.alias
   el.for = false // avoid recursion
-  return `(${exp}) && (${exp}).map(function (${alias}, $index) {return ${genElement(el)}})`
+  return `(${exp})&&(${exp}).map(function(${alias},$index) {return ${genElement(el)}})`
 }
 
 function genData (el) {

+ 1 - 0
src/runtime/instance/render.js

@@ -123,6 +123,7 @@ export function renderMixin (Vue) {
       mergeParentDirectives(this, data, _renderData)
       updateParentCallbacks(this, data, _renderData)
     }
+    console.log(vnode)
     return vnode
   }
 

+ 7 - 11
src/runtime/vdom/create-element.js

@@ -40,19 +40,15 @@ function flatten (children) {
   if (isArray(children)) {
     let res = []
     for (let i = 0, l = children.length; i < l; i++) {
-      let e = children[i]
+      let c = children[i]
       // flatten nested
-      if (isArray(e)) {
-        for (let j = 0, k = e.length; j < k; j++) {
-          if (e[j]) {
-            res.push(e[j])
-          }
-        }
-      } else if (isPrimitive(e)) {
+      if (isArray(c)) {
+        res.push.apply(res, flatten(c))
+      } else if (isPrimitive(c)) {
         // convert primitive to vnode
-        res.push(VNode(undefined, undefined, undefined, e))
-      } else if (e) {
-        res.push(e)
+        res.push(VNode(undefined, undefined, undefined, c))
+      } else if (c) {
+        res.push(c)
       }
     }
     return res