Skip to content

Commit a3988f1

Browse files
committed
fix(mp): 修复混合分包时报错找不到 $callHook 的问题
1 parent 0718f8e commit a3988f1

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

packages/uni-mp-core/src/runtime/app.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
ref,
77
} from 'vue'
88

9-
import { initBaseInstance } from './componentInstance'
9+
import { callHook, hasHook, initBaseInstance } from './componentInstance'
1010
import { initHooks, initRuntimeHooks, initUnknownHooks } from './componentHooks'
1111
import { getLocaleLanguage } from '../runtime/util'
1212

@@ -127,6 +127,8 @@ export function initCreateSubpackageApp(parseAppOptions?: ParseAppOptions) {
127127
})
128128
if (!app) return
129129
;(vm.$ as any).ctx.$scope = app
130+
;(vm.$ as any).ctx.$hasHook = hasHook
131+
;(vm.$ as any).ctx.$callHook = callHook
130132
const globalData = app.globalData
131133
if (globalData) {
132134
Object.keys(appOptions.globalData).forEach((name) => {

packages/uni-mp-core/src/runtime/componentInstance.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,19 @@ export function initMocks(
199199
})
200200
}
201201

202-
function hasHook(this: ComponentPublicInstance, name: string) {
202+
export function hasHook(this: ComponentPublicInstance, name: string) {
203203
const hooks = (this.$ as any)[name]
204204
if (hooks && hooks.length) {
205205
return true
206206
}
207207
return false
208208
}
209209

210-
function callHook(this: ComponentPublicInstance, name: string, args?: unknown) {
210+
export function callHook(
211+
this: ComponentPublicInstance,
212+
name: string,
213+
args?: unknown
214+
) {
211215
if (name === 'mounted') {
212216
callHook.call(this, 'bm') // beforeMount
213217
this.$.isMounted = true

0 commit comments

Comments
 (0)