Skip to content

Commit 95b9b52

Browse files
perymimonfoxbenjaminfox
authored andcommitted
fix: data (as a function) of component not got vm as argument in init function
1 parent ac7b60e commit 95b9b52

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

Diff for: src/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ const AsyncComputed = {
3939
this.$options.computed[prefix + key] = getter
4040
}
4141

42-
this.$options.data = function vueAsyncComputedInjectedDataFn () {
42+
this.$options.data = function vueAsyncComputedInjectedDataFn (vm) {
4343
const data = (
4444
(typeof optionData === 'function')
45-
? optionData.call(this)
45+
? optionData.call(this, vm)
4646
: optionData
4747
) || {}
4848
for (const key in asyncComputed) {

Diff for: test/index.js

+17
Original file line numberDiff line numberDiff line change
@@ -868,3 +868,20 @@ test("Plain components with neither `data` nor `asyncComputed` still work (issue
868868
})
869869
t.equal(vm.a, 1)
870870
})
871+
872+
test('Data of component still work as function and got vm', t => {
873+
t.plan(1)
874+
let _vmContext = null
875+
const vm = new Vue({
876+
data (vmContext) {
877+
_vmContext = vmContext
878+
},
879+
asyncComputed: {
880+
async a () {
881+
return Promise.resolve(1)
882+
},
883+
},
884+
885+
})
886+
t.equal(vm, _vmContext)
887+
})

0 commit comments

Comments
 (0)