Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: fix v-for component with undefined value
fix #9181
  • Loading branch information
yyx990803 committed Dec 11, 2018
1 parent 984393f commit 4748760
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/core/vdom/helpers/normalize-children.js
Expand Up @@ -16,6 +16,9 @@ import { isFalse, isTrue, isDef, isUndef, isPrimitive } from 'shared/util'
// thing with Array.prototype.concat. It is guaranteed to be only 1-level deep
// because functional components already normalize their own children.
export function simpleNormalizeChildren (children: any) {
if (!Array.isArray(children)) {
return
}
for (let i = 0; i < children.length; i++) {
if (Array.isArray(children[i])) {
return Array.prototype.concat.apply([], children)
Expand Down
23 changes: 23 additions & 0 deletions test/unit/features/directives/for.spec.js
Expand Up @@ -484,6 +484,29 @@ describe('Directive v-for', () => {
expect(vm.$el.textContent).toBe('12')
})

// #9181
it('components with v-for and empty list', done => {
const vm = new Vue({
template:
'<div attr>' +
'<foo v-for="item in list">{{ item }}</foo>' +
'</div>',
data: {
list: undefined
},
components: {
foo: {
template: '<div><slot></slot></div>'
},
}
}).$mount()
expect(vm.$el.innerHTML).toBe('')
vm.list = [1, 2, 3]
waitForUpdate(() => {
expect(vm.$el.innerHTML).toBe('<div>1</div><div>2</div><div>3</div>')
}).then(done)
})

const supportsDestructuring = (() => {
try {
new Function('var { foo } = bar')
Expand Down

0 comments on commit 4748760

Please sign in to comment.