fix(ref): allow ref key to be zero (#7676)

prevents missing elements when :ref value is "0"

fix #7669
This commit is contained in:
TB 2018-02-21 15:21:51 +00:00 committed by Evan You
parent 4e6d6379ee
commit e396eb3445
2 changed files with 9 additions and 2 deletions

View File

@ -1,6 +1,6 @@
/* @flow */
import { remove } from 'shared/util'
import { remove, isDef } from 'shared/util'
export default {
create (_: any, vnode: VNodeWithData) {
@ -19,7 +19,7 @@ export default {
export function registerRef (vnode: VNodeWithData, isRemoval: ?boolean) {
const key = vnode.data.ref
if (!key) return
if (!isDef(key)) return
const vm = vnode.context
const ref = vnode.componentInstance || vnode.elm

View File

@ -9,6 +9,10 @@ describe('ref', () => {
test2: {
id: 'test2',
template: '<div>test2</div>'
},
test3: {
id: 'test3',
template: '<div>test3</div>'
}
}
@ -20,6 +24,7 @@ describe('ref', () => {
template: `<div>
<test ref="foo"></test>
<test2 :ref="value"></test2>
<test3 :ref="0"></test3>
</div>`,
components
})
@ -28,6 +33,8 @@ describe('ref', () => {
expect(vm.$refs.foo.$options.id).toBe('test')
expect(vm.$refs.bar).toBeTruthy()
expect(vm.$refs.bar.$options.id).toBe('test2')
expect(vm.$refs['0']).toBeTruthy()
expect(vm.$refs['0'].$options.id).toBe('test3')
})
it('should dynamically update refs', done => {