没有提供直接在Navigation组件和NavDestination组件之间实现数据传递的装饰器。
可以参考以下方式,通过api调用的方式实现参数传递
https://gitee.com/openharmony/docs/blob/master/zh-cn/applicat...
“应用导航设计”的demo示例中针对B1.ets文件做如下修改,在onShown方法中可以实现在页面加载之前的方法调用,参考代码如下:
import { BuilderNameConstants, buildRouterModel, RouterModule, RouterNameConstants, } from '@ohos/routermodule';
import http from '@ohos.net.http';
@Builder
export function harBuilder(value: object) {
NavDestination() {
Column() {
Button($r("app.string.to_harb_pageB2"), { stateEffect: true, type: ButtonType.Capsule })
.width('80%')
.height(40)
.margin(20)
.onClick(() => {
buildRouterModel(RouterNameConstants.ENTRY_HAP, BuilderNameConstants.HARB_B2);
})
}
.width('100%')
.height('100%')
}
.onShown(() => {
// http请求网络资源数据
let httpRequest = http.createHttp();
httpRequest.request("your url", (err, data) => {
if (!err) {
console.info('Result:' + data.result);
console.info('code:' + data.responseCode);
console.info('header:' + JSON.stringify(data.header));
console.info('cookies:' + data.cookies); // 8+
} else {
console.info('error:' + JSON.stringify(err));
}
});
})
.title('B1Page')
.onBackPressed(() => {
RouterModule.pop(RouterNameConstants.ENTRY_HAP);
return true;
})
}
const builderName = BuilderNameConstants.HARB_B1;
if (!RouterModule.getBuilder(builderName)) {
let builder: WrappedBuilder<[object]> = wrapBuilder(harBuilder);
RouterModule.registerBuilder(builderName, builder);
}
6 天前