HarmonyOS 鸿蒙Next中HMRouter传参问题
HarmonyOS 鸿蒙Next中HMRouter传参问题
HMRouter传参可以A->B,但是不能A->B->C,可能还有c->A,代码
A:界面代码
Refresh({ refreshing: $$this.refreshing, builder: this.refreshBuilder() }){
List({ space: 3}) {
ForEach((this.toBeSent), (item: toBeSentData,index:number) => {
ListItem() {
Column() {
Row() {
Text(item.title)
.fontColor('#000000')
.fontSize(20)
Text(this.getStateInfo(item.status).text)
.fontSize(20)
.fontColor(this.getStateInfo(item.status).color)
}
.width('100%')
.justifyContent(FlexAlign.SpaceBetween)
.padding({left:14,right:14,bottom:11,top:10})
.height(29)
Row() {
Image($r('[base].media.time'))
.width(25)
.aspectRatio(1)
Text(item.upDateTime)
.fontColor('#595959')
.fontSize(13)
}
.width('100%')
.justifyContent(FlexAlign.Start)
.padding({left:16,right:16,top:11})
}.width('100%')
.height(80)
.backgroundColor(this.getStateInfo(item.status).backgroundColor)
.borderRadius(8)
.onClick(()=>{
HMRouterMgr.push({pageUrl:PAGE_PATH.to_be_sent_edit,param:item})
})
}
.swipeAction({
end: {
builder: () => {
this.itemEnd(index)
},
},
})
})
ListItem() {
this.footer();
}
ListItem(){
Column().width('100%').height(160)
}
}.onScrollIndex((start: number, end: number) => {
if (end >= this.toBeSent.length - 1) {
this.isLoading = true;
setTimeout(() => {
for (let i = 0; i < 10; i++) {
const item: toBeSentData = {
id: `i`,
upDateTime: 'Last Updated:2025/03/14',
stateDateTime: '',
title: 'To Matthew Riley',
status: 6,
list:[],
}
this.toBeSent.push(item);
}
this.isLoading = false;
}, 700)
}
})
.scrollBar(BarState.Off)
.edgeEffect(EdgeEffect.Spring, { alwaysEnabled: true })
B界面代码展示没有问题
aboutToAppear(): void { this.item = HMRouterMgr.getCurrentParam() as toBeSentData }获取到的前面列表内容并且可以展示
B界面传递出去
Image($r('[base].media.edit')).width(20).aspectRatio(1)
.onClick(()=>{
HMRouterMgr.push({ pageUrl: PAGE_PATH.recipient_designation, param:{ here:'Edit Recipient Information', item:this.item } })
})
c界面
export interface ResetPasswordOne{
here:string;
}
export interface bucketListEdit{
here:ResetPasswordOne,
item:bucketList
}
export interface ListItem {
id:string;
text: string;
image:string;
}
export interface CustomListItem {
id:string;
text: string;
image: string;
}
export interface toBeSentData {
id: string;
upDateTime: string;
stateDateTime: string;
title: string;
status: number;
list: ListItem[];
}
数据
@Local toBeSent:toBeSentData[]=[
{
id:'01',
upDateTime: 'Last Updated :2025/04/03',
stateDateTime: '',
title: 'To Charlotte Smith',
status: 1,
list:[
{
id:'01',
text:"Dear my love If you're reading this, it means I'm no longer with you. Please know that my love for you will never fade, no matter where l am. You were the greatest gift in my life, and every moment we shared will forever be my most cherished memory.",
image:'[base].media.test1'
},
{
id:'02',
text:"Be strong, as l know you are, and always remember that l am with you in spirit.",
image:'[base].media.test2'
},
],
},
{
id:'02',
upDateTime: 'Last Updated :2025/04/03',
stateDateTime: '',
title: 'To luna Smith',
status: 2,
list:[],
},
{
id:'03',
upDateTime: 'Last Updated:2025/03/14',
stateDateTime: '',
title: 'To Alan White',
status: 3,
list:[],
},
{
id:'04',
upDateTime: 'Last Updated:2025/03/14',
stateDateTime: '',
title: 'To William White',
status: 4,
list:[],
},
{
id:'05',
upDateTime: 'Last Updated:2025/03/14',
stateDateTime: '',
title: 'To James Brown',
status: 5,
list:[],
},
{
id:'06',
upDateTime: 'Last Updated:2025/03/14',
stateDateTime: '',
title: 'To Matthew Riley',
status: 6,
list:[],
},
]
更多关于HarmonyOS 鸿蒙Next中HMRouter传参问题的实战教程也可以访问 https://www.itying.com/category-93-b0.html
2 回复
在鸿蒙Next中,HMRouter传参可通过以下方式实现:
- 使用
parameters
属性传递基本类型参数:
router.pushUrl({
url: 'pages/TargetPage',
parameters: {id: '123', name: 'test'}
})
- 目标页面通过
router.getParams()
获取参数:
onPageShow() {
const params = router.getParams()
let id = params['id']
}
-
传递对象参数需先序列化为JSON字符串,接收方再反序列化。
-
注意参数总长度不超过100KB。
更多关于HarmonyOS 鸿蒙Next中HMRouter传参问题的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html