Просмотр исходного кода

Update normalize children (fix 4466) (#4468)

* omit boolean node

* add test case

* update boolean type

* update test case

* update test case
chengchao 9 лет назад
Родитель
Сommit
6918436bf8

+ 1 - 1
src/core/vdom/helpers/normalize-children.js

@@ -16,7 +16,7 @@ function normalizeArrayChildren (children: any, nestedIndex?: string): Array<VNo
   let i, c, last
   for (i = 0; i < children.length; i++) {
     c = children[i]
-    if (c == null) continue
+    if (c == null || typeof c === 'boolean') continue
     last = res[res.length - 1]
     //  nested
     if (Array.isArray(c)) {

+ 11 - 0
test/unit/modules/vdom/create-element.spec.js

@@ -98,6 +98,17 @@ describe('create-element', () => {
     expect(vnode.children[2].tag).toBe('br')
   })
 
+  it('render vnode with children, including boolean and null type', () => {
+    const vm = new Vue({})
+    const h = vm.$createElement
+    const vnode = h('p', [h('br'), true, 123, h('br'), 'abc', null])
+    expect(vnode.children.length).toBe(4)
+    expect(vnode.children[0].tag).toBe('br')
+    expect(vnode.children[1].text).toBe('123')
+    expect(vnode.children[2].tag).toBe('br')
+    expect(vnode.children[3].text).toBe('abc')
+  })
+
   it('render svg elements with correct namespace', () => {
     const vm = new Vue({})
     const h = vm.$createElement