Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/uni-mp-core/src/runtime/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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) => {
Expand Down
8 changes: 6 additions & 2 deletions packages/uni-mp-core/src/runtime/componentInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,19 @@ 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
}
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
Expand Down
Loading