diff --git a/src/core/util/options.js b/src/core/util/options.js index 3a86509ae74..d2c069cfb83 100644 --- a/src/core/util/options.js +++ b/src/core/util/options.js @@ -195,7 +195,6 @@ strats.watch = function (parentVal: ?Object, childVal: ?Object): ?Object { */ strats.props = strats.methods = -strats.inject = strats.computed = function (parentVal: ?Object, childVal: ?Object): ?Object { if (!childVal) return Object.create(parentVal || null) if (!parentVal) return childVal @@ -204,6 +203,12 @@ strats.computed = function (parentVal: ?Object, childVal: ?Object): ?Object { extend(ret, childVal) return ret } +strats.inject = function (parentVal: ?Object, childVal: ?Object): ?Object { + const ret = {} + extend(ret, parentVal) + extend(ret, childVal) + return ret +} strats.provide = mergeDataOrFn /** diff --git a/test/unit/features/options/inject.spec.js b/test/unit/features/options/inject.spec.js index ba95d949a0a..839cec8af7b 100644 --- a/test/unit/features/options/inject.spec.js +++ b/test/unit/features/options/inject.spec.js @@ -442,4 +442,25 @@ describe('Options provide/inject', () => { expect(isObserver(child.bar)).toBe(false) expect(isObserver(child.baz)).toBe(false) }) + + // #6093 + it('should merge inject from mixins properly', () => { + const mixinA = { inject: ['foo'] } + const mixinB = { inject: ['bar'] } + const child = { + template: ``, + mixins: [mixinA, mixinB], + created () { + injected = [this.foo, this.bar] + } + } + new Vue({ + provide: { foo: 'foo', bar: 'bar' }, + render (h) { + return h(child) + } + }).$mount() + + expect(injected).toEqual(['foo', 'bar']) + }) })