From 3c216755f6eb656c6d864265a8dc7b51b3ae971b Mon Sep 17 00:00:00 2001 From: JK Date: Wed, 6 Sep 2017 04:01:50 +0800 Subject: [PATCH] fix(provide): provide should default to parentVal during merging (#6473) fix #6436 --- src/core/util/options.js | 2 +- test/unit/features/options/inject.spec.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/core/util/options.js b/src/core/util/options.js index 0d4f4eeea..70e4d015b 100644 --- a/src/core/util/options.js +++ b/src/core/util/options.js @@ -96,7 +96,7 @@ export function mergeDataOrFn ( : childVal const defaultData = typeof parentVal === 'function' ? parentVal.call(vm) - : undefined + : parentVal if (instanceData) { return mergeData(instanceData, defaultData) } else { diff --git a/test/unit/features/options/inject.spec.js b/test/unit/features/options/inject.spec.js index e4d9f90e5..61111a7d4 100644 --- a/test/unit/features/options/inject.spec.js +++ b/test/unit/features/options/inject.spec.js @@ -545,4 +545,24 @@ describe('Options provide/inject', () => { expect(vm.$el.textContent).toBe(`foo: foo injected, bar: bar injected`) }) + + it('merge provide with object syntax when using Vue.extend', () => { + const child = { + inject: ['foo'], + template: ``, + created () { + injected = this.foo + } + } + const Ctor = Vue.extend({ + provide: { foo: 'foo' }, + render (h) { + return h(child) + } + }) + + new Ctor().$mount() + + expect(injected).toEqual('foo') + }) })