HarmonyOS navigation进行组件跳转如何通知刷新UI?

使用navigation进行组件跳转。现在 最后一个页面添加了一个设备 返回到第一个navigation的设备列表页面,怎么通知刷新设备列表。有方法推荐吗

阅读 632
1 个回答

可以通过NavDestination的onShown来实现,onShown会在NavDestination页面显示时触发此回调。

export class Pages2 {
  names: string = ""
  values: NavPathStack | null = null
}

@Builder
export function pageThreeTmp(info: Pages2) {

  NavDestination() {
    Column() {
      Button('pushPathByName', { stateEffect: true, type: ButtonType.Capsule })
        .width('80%')
        .height(40)
        .margin(20)
        .onClick(() => {
          (info.values as NavPathStack).pushPathByName('pageOne', null)
        })
    }.width('100%').height('100%')
  }.title('pageThree')
  .onBackPressed(() => {
    (info.values as NavPathStack).pop()
    return true
  })
  .onShown(()=>{
    console.log('123123')
  })
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进