Skip to content

Commit bd38894

Browse files
authored
Merge pull request #2153 from didi/fix-getcurrentinstance
fix: 修复选项式api下生命周期中getCurrentInstance为空问题
2 parents 4503e34 + 73ff456 commit bd38894

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

packages/core/src/core/proxy.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,11 +501,19 @@ export default class MpxProxy {
501501
const hooks = this.hooks[hookName] || []
502502
let result
503503
if (isFunction(hook) && !hooksOnly) {
504+
const setContext = hookName !== BEFORECREATE
505+
if (setContext) {
506+
setCurrentInstance(this)
507+
}
504508
result = callWithErrorHandling(hook.bind(this.target), this, `${hookName} hook`, params)
509+
if (setContext) {
510+
unsetCurrentInstance()
511+
}
505512
}
506513
hooks.forEach((hook) => {
507514
result = params ? hook(...params) : hook()
508515
})
516+
509517
return result
510518
}
511519

0 commit comments

Comments
 (0)