可以通过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') }) }
可以通过NavDestination的onShown来实现,onShown会在NavDestination页面显示时触发此回调。