From a3988f12d5a409cedb9b1e3968c79737a5e64e2c Mon Sep 17 00:00:00 2001 From: chouchouji <1305974212@qq.com> Date: Thu, 19 Mar 2026 16:28:04 +0800 Subject: [PATCH] =?UTF-8?q?fix(mp):=20=E4=BF=AE=E5=A4=8D=E6=B7=B7=E5=90=88?= =?UTF-8?q?=E5=88=86=E5=8C=85=E6=97=B6=E6=8A=A5=E9=94=99=E6=89=BE=E4=B8=8D?= =?UTF-8?q?=E5=88=B0=20$callHook=20=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/uni-mp-core/src/runtime/app.ts | 4 +++- packages/uni-mp-core/src/runtime/componentInstance.ts | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/uni-mp-core/src/runtime/app.ts b/packages/uni-mp-core/src/runtime/app.ts index 32b20b1cbc..ad13c4d858 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, initRuntimeHooks, initUnknownHooks } from './componentHooks' import { getLocaleLanguage } from '../runtime/util' @@ -127,6 +127,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 09beffc11c..4f9e780a68 100644 --- a/packages/uni-mp-core/src/runtime/componentInstance.ts +++ b/packages/uni-mp-core/src/runtime/componentInstance.ts @@ -199,7 +199,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 @@ -207,7 +207,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