HarmonyOS tabContent onPageShow 方法不生效,如何监听页面回到前台?

tabContent onPageShow 方法 不生效,如何监听页面回到前台。

1.点击不同的 tab切换 tabContent 内容。

2.从其他页面返回时。

HarmonyOS
2024-10-22 11:22:07
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
superinsect

tabContent  onPageShow 方法 不生效。可以采用监听tabContent 里面页面的属性来实现,然后通过Tabs的onPageShow 来改变属性,实现监听。

示例代码如下:

Home.ets

@Link @Watch('customShow') timer: Number  
customShow(){  
  this.getUIContext().getPromptAction().showToast({  
    message: "Home页面展示"  
  });  
}  
MainPage.ets  
@State HomeTimer: number = 0;  
Home({  
  timer:$HomeTimer  
})  
onPageShow() {  
  if (this.currentPageIndex == 0) { //Home  
    this.HomeTimer = this.timeStamp()  
  } else if(this.currentPageIndex == 1) {//Message  
  
  }  
}  
  
timeStamp(){  
  return new Date().getTime();  
}
分享
微博
QQ
微信
回复
2024-10-22 17:17:17
相关问题
HarmonyOS 如何监听前台应用切换
1031浏览 • 1回复 待解决
HarmonyOS TabContent页面生命周期触发
1695浏览 • 1回复 待解决
HarmonyOS navigation触发onpageshow
706浏览 • 1回复 待解决
HarmonyOS 如何监听app从后台切换到前台
1530浏览 • 1回复 待解决