一、使用router路由跳转页面并携带参数
1、导入库
import router from '@kit.ArkUI';
2、跳转页面并携带参数
export class ActivityResponse {
......
}
(1)携带多个参数
router.pushUrl({
url: 'pages/NextPage',
params: {
name: '名字', //string类型
avator: '头像', //string类型
size: 大小, //number类型
responsedata: '某个对象数据' //ActivityResponse类型
}
})
NextPage页解析:
private responseData: ActivityResponse = new ActivityResponse();
private name: string = ''
private avator: string = ''
private size: number = 0
......
let params = router.getParams() as Record<string, number | string | ActivityResponse>;
this.responseData= params.result as ActivityResponse;
this.name= params.uri as string;
this.avator= params.infoW as string;
this.size= params.infoH as number;
(2)携带一个参数,参数是类对象
在参数过多的情况下,可以将传递的参数封装为类,以对象方式传递更方便接收解析
private curr_data: ActivityResponse = new ActivityResponse();
......
router.pushUrl({
url: 'pages/NextPage',
params: this.curr_data
},router.RouterMode.Standard,(err)=>{
if (err) {
console.error(`跳转页面失败, code is ${err.code}, message is ${err.message}`);
return;
}
})
NextPage页解析:
this.params = router.getParams() as ActivityResponse;
二、使用navigation
未完,待续