From e396eb3445904f11232f2355f03e8356173d0e31 Mon Sep 17 00:00:00 2001 From: TB Date: Wed, 21 Feb 2018 15:21:51 +0000 Subject: [PATCH] fix(ref): allow ref key to be zero (#7676) prevents missing elements when :ref value is "0" fix #7669 --- src/core/vdom/modules/ref.js | 4 ++-- test/unit/features/ref.spec.js | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/core/vdom/modules/ref.js b/src/core/vdom/modules/ref.js index 00bb5f52709..aa9bdcfcfba 100644 --- a/src/core/vdom/modules/ref.js +++ b/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) { @@ -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 diff --git a/test/unit/features/ref.spec.js b/test/unit/features/ref.spec.js index 05efc4d5244..971c8fbe678 100644 --- a/test/unit/features/ref.spec.js +++ b/test/unit/features/ref.spec.js @@ -9,6 +9,10 @@ describe('ref', () => { test2: { id: 'test2', template: '
test2
' + }, + test3: { + id: 'test3', + template: '
test3
' } } @@ -20,6 +24,7 @@ describe('ref', () => { template: `
+
`, 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 => {