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

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

阅读 515
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)
})
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进