diff --git a/packages/uni-mp-core/src/runtime/app.ts b/packages/uni-mp-core/src/runtime/app.ts index 06c28183d23..8a21abc7e6d 100644 --- a/packages/uni-mp-core/src/runtime/app.ts +++ b/packages/uni-mp-core/src/runtime/app.ts @@ -6,7 +6,7 @@ import { ref, } from 'vue' -import { initBaseInstance } from './componentInstance' +import { callHook, hasHook, initBaseInstance } from './componentInstance' import { initHooks, initUnknownHooks } from './componentHooks' import { getLocaleLanguage } from '../runtime/util' @@ -123,6 +123,8 @@ export function initCreateSubpackageApp(parseAppOptions?: ParseAppOptions) { }) if (!app) return ;(vm.$ as any).ctx.$scope = app + ;(vm.$ as any).ctx.$hasHook = hasHook + ;(vm.$ as any).ctx.$callHook = callHook const globalData = app.globalData if (globalData) { Object.keys(appOptions.globalData).forEach((name) => { diff --git a/packages/uni-mp-core/src/runtime/componentInstance.ts b/packages/uni-mp-core/src/runtime/componentInstance.ts index 8a1e1407e08..00fddfd01a4 100644 --- a/packages/uni-mp-core/src/runtime/componentInstance.ts +++ b/packages/uni-mp-core/src/runtime/componentInstance.ts @@ -187,7 +187,7 @@ export function initMocks( }) } -function hasHook(this: ComponentPublicInstance, name: string) { +export function hasHook(this: ComponentPublicInstance, name: string) { const hooks = (this.$ as any)[name] if (hooks && hooks.length) { return true @@ -195,7 +195,11 @@ function hasHook(this: ComponentPublicInstance, name: string) { return false } -function callHook(this: ComponentPublicInstance, name: string, args?: unknown) { +export function callHook( + this: ComponentPublicInstance, + name: string, + args?: unknown +) { if (name === 'mounted') { callHook.call(this, 'bm') // beforeMount this.$.isMounted = true