Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/core/util/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

/**
Expand Down
21 changes: 21 additions & 0 deletions test/unit/features/options/inject.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: `<span/>`,
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'])
})
})