mirror of
https://gitee.com/vuejs/vue.git
synced 2024-12-04 13:07:40 +08:00
fix(ref): allow ref key to be zero (#7676)
prevents missing elements when :ref value is "0" fix #7669
This commit is contained in:
parent
4e6d6379ee
commit
e396eb3445
@ -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
|
||||
|
@ -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 => {
|
||||
|
Loading…
Reference in New Issue
Block a user