提交 75d07614 编写于 作者: fxy060608's avatar fxy060608

fix(h5): onLoad

上级 2e1f2ac1
......@@ -33,13 +33,17 @@ import { initLaunchOptions, getEnterOptions } from './utils'
interface SetupComponentOptions {
init: (vm: ComponentPublicInstance) => void
setup: (instance: ComponentInternalInstance) => Record<string, any> | void
setup: (instance: ComponentInternalInstance) => Record<string, unknown> | void
afterSetup?: (
instance: ComponentInternalInstance,
query: Record<string, unknown>
) => void
before?: (comp: DefineComponent) => void
}
function wrapperComponentSetup(
comp: DefineComponent,
{ init, setup, before }: SetupComponentOptions
{ init, setup, before, afterSetup }: SetupComponentOptions
) {
before && before(comp)
const oldSetup = comp.setup
......@@ -50,6 +54,9 @@ function wrapperComponentSetup(
if (oldSetup) {
return oldSetup(query || props, ctx)
}
if (afterSetup) {
afterSetup(instance, query!)
}
}
}
......@@ -78,6 +85,11 @@ export function setupWindow(comp: any, id: number) {
export function setupPage(comp: any) {
return setupComponent(comp, {
init: initPage,
afterSetup(instance, query) {
// 因为 onLoad 是在 setup 执行过程中添加的,故需要放在 after 中执行
const { onLoad } = instance
onLoad && invokeArrayFns(onLoad, decodedQuery(query))
},
setup(instance) {
instance.root = instance // 组件 root 指向页面
const route = usePageRoute()
......@@ -89,12 +101,9 @@ export function setupPage(comp: any) {
})
return route.query
}
const pageMeta = usePageMeta()
// 放在 onMounted 中,可以保证子组件中监听的相关生命周期也可以触发,比如onShow,onPageScroll
const { onLoad } = instance
onLoad && invokeArrayFns(onLoad, decodedQuery(route.query))
onMounted(() => {
// 放在 onMounted 中,可以保证子组件中监听的相关生命周期也可以触发,比如onShow,onPageScroll
onPageShow(instance, pageMeta)
const { onShow } = instance
instance.__isVisible = true
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册