HarmonyOS 一进入页面就会走的方法?

类似于其他系统的UIViewController 的 viewWillAppear 方法

阅读 516
1 个回答

可以使用onPageShow方法仅@Entry装饰的自定义组件生效:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-custom-component-lifecycle-V5\#onpageshow

或者使用onVisibleAreaChange:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-universal-component-visible-area-change-event-V5\#onvisibleareachange

.onVisibleAreaChange([0.0, 1.0], (isVisible: boolean, currentRatio: number) => {
  console.log('Test isVisible:' + isVisible + ', currentRatio:' + currentRatio)
})