diff --git a/src/core/instance/state.js b/src/core/instance/state.js index f6770325506..017e1694f8b 100644 --- a/src/core/instance/state.js +++ b/src/core/instance/state.js @@ -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 {} diff --git a/test/unit/features/options/data.spec.js b/test/unit/features/options/data.spec.js index 7838ed39af2..29a48c38b44 100644 --- a/test/unit/features/options/data.spec.js +++ b/test/unit/features/options/data.spec.js @@ -106,4 +106,21 @@ describe('Options data', () => { }) expect(vm.a).toBe(1) }) + + it('should called with this', () => { + const vm = new Vue({ + template: '
', + provide: { foo: 1 }, + components: { + child: { + template: '{{bar}}', + inject: ['foo'], + data ({ foo }) { + return { bar: 'foo:' + foo } + } + } + } + }).$mount() + expect(vm.$el.innerHTML).toBe('foo:1') + }) })