Skip to content

Commit

Permalink
fix(ref): allow ref key to be zero (#7676)
Browse files Browse the repository at this point in the history
prevents missing elements when :ref value is "0"

fix #7669
  • Loading branch information
t0mburton authored and yyx990803 committed Feb 21, 2018
1 parent 4e6d637 commit e396eb3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core/vdom/modules/ref.js
@@ -1,6 +1,6 @@
/* @flow */

import { remove } from 'shared/util'
import { remove, isDef } from 'shared/util'

export default {
create (_: any, vnode: VNodeWithData) {
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions test/unit/features/ref.spec.js
Expand Up @@ -9,6 +9,10 @@ describe('ref', () => {
test2: {
id: 'test2',
template: '<div>test2</div>'
},
test3: {
id: 'test3',
template: '<div>test3</div>'
}
}

Expand All @@ -20,6 +24,7 @@ describe('ref', () => {
template: `<div>
<test ref="foo"></test>
<test2 :ref="value"></test2>
<test3 :ref="0"></test3>
</div>`,
components
})
Expand All @@ -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 => {
Expand Down

0 comments on commit e396eb3

Please sign in to comment.