Skip to content

Fix 7191 - data arg merge #7192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 6, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 4 additions & 4 deletions src/core/util/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,18 @@ export function mergeDataOrFn (
// it has to be a function to pass previous merges.
return function mergedDataFn () {
return mergeData(
typeof childVal === 'function' ? childVal.call(this) : childVal,
typeof parentVal === 'function' ? parentVal.call(this) : parentVal
typeof childVal === 'function' ? childVal.call(this, this) : childVal,
typeof parentVal === 'function' ? parentVal.call(this, this) : parentVal
)
}
} else {
return function mergedInstanceDataFn () {
// instance merge
const instanceData = typeof childVal === 'function'
? childVal.call(vm)
? childVal.call(vm, vm)
: childVal
const defaultData = typeof parentVal === 'function'
? parentVal.call(vm)
? parentVal.call(vm, vm)
: parentVal
if (instanceData) {
return mergeData(instanceData, defaultData)
Expand Down
28 changes: 28 additions & 0 deletions test/unit/features/options/data.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,32 @@ describe('Options data', () => {
}).$mount()
expect(vm.$el.innerHTML).toBe('<span>foo:1</span>')
})

it('should called with this when merged', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be

const superComponent = {
data: ({ foo }) => ({ ext: 'ext:' + foo })
}
const mixins = [
{
data: ({ foo }) => ({ mixin1: 'm1:' + foo })
},
{
data: ({ foo }) => ({ mixin2: 'm2:' + foo })
}
]
const vm = new Vue({
template: '<div><child></child></div>',
provide: { foo: 1 },
components: {
child: {
extends: superComponent,
mixins,
template: '<span>{{bar}}-{{ext}}-{{mixin1}}-{{mixin2}}</span>',
inject: ['foo'],
data: ({ foo }) => ({ bar: 'foo:' + foo })
}
}
}).$mount()
expect(vm.$el.innerHTML).toBe('<span>foo:1-ext:1-m1:1-m2:1</span>')
})
})