mirror of
https://gitee.com/vuejs/vue.git
synced 2024-11-30 11:07:51 +08:00
parent
596257cf6f
commit
3a5432a9e3
@ -161,7 +161,7 @@ function initData (vm: Component) {
|
||||
|
||||
function getData (data: Function, vm: Component): any {
|
||||
try {
|
||||
return data.call(vm)
|
||||
return data.call(vm, vm)
|
||||
} catch (e) {
|
||||
handleError(e, vm, `data()`)
|
||||
return {}
|
||||
|
@ -106,4 +106,21 @@ describe('Options data', () => {
|
||||
})
|
||||
expect(vm.a).toBe(1)
|
||||
})
|
||||
|
||||
it('should called with this', () => {
|
||||
const vm = new Vue({
|
||||
template: '<div><child></child></div>',
|
||||
provide: { foo: 1 },
|
||||
components: {
|
||||
child: {
|
||||
template: '<span>{{bar}}</span>',
|
||||
inject: ['foo'],
|
||||
data ({ foo }) {
|
||||
return { bar: 'foo:' + foo }
|
||||
}
|
||||
}
|
||||
}
|
||||
}).$mount()
|
||||
expect(vm.$el.innerHTML).toBe('<span>foo:1</span>')
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user