HarmonyOS 鸿蒙Next Navigation 组建里面的子界面跳转带参数返回
HarmonyOS 鸿蒙Next Navigation 组建里面的子界面跳转带参数返回
A子界面跳到B子界面 B处理完业务后带参数返回A子界面 然后A界面进行接收参数操作
官网上是这样
// pop B页面
this.pathInfos.pop();
//获取当前栈顶页面名字(A页面)
let allPathName: Array<string> = this.pathInfos.getAllPathName();
let pathNameA: string = allPathName[allPathName.length - 1];
// pop A页面
this.pathInfos.pop();
// 重新PUSH A页面
this.pathInfos.pushPath(new NavPathInfo(pathNameA, this.routerParams))
但是这个会让A重载2次,A界面进去加载的东西有点多,不够流畅,有没有类型安卓上EVENbus组件能全局监听 或者有其他的更好的解决方案吗
更多关于HarmonyOS 鸿蒙Next Navigation 组建里面的子界面跳转带参数返回的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
更多关于HarmonyOS 鸿蒙Next Navigation 组建里面的子界面跳转带参数返回的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
import { hilog } from '@kit.PerformanceAnalysisKit';
@Entry @ComponentV2 struct Index { private pathStack = new NavPathStack() @Local text: string = “”
build() { Navigation(this.pathStack) { Column() { Button(‘go child’).onClick(() => { this.pathStack.pushPathByName(‘child’, null, (info: PopInfo) => { if (info && info.result) { this.text = info.result.toString() hilog.debug(0x000000, ‘rainrain’, 'result == ’ + info.result.toString()) } }) }) Text('收到的数据 === ’ + this.text) } }.size({ width: ‘100%’, height: ‘100%’ }) .hideTitleBar(false) .hideToolBar(false) .navDestination(this.BuilderMap) }
@Builder BuilderMap() { ChildPage() } }
@ComponentV2 struct ChildPage { build() { NavDestination() { Column() { Button(‘pop with param’).onClick(() => { this.queryNavigationInfo()?.pathStack.pop(‘one str’) }) Button(‘pop no param’).onClick(() => { this.queryNavigationInfo()?.pathStack.pop() }) } }.size({ width: ‘100%’, height: ‘100%’ }) } }