HarmonyOS router.pushNamedRoute参数传递 在接收页面怎么接收

HarmonyOS
2024-12-18 14:46:02
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
zbw_apple

可以通过router.getParams();接收参数,API链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-router-V5#ZH-CN_TOPIC_0000001884917590__routergetparams

参考demo如下:

import router from '@ohos.router';
class innerParams {
  array:number[]
  constructor(tuple:number[]) {
    this.array = tuple
  }
}

class routerParams {
  text:string
  data:innerParams
  constructor(str:string, tuple:number[]) {
    this.text = str
    this.data = new innerParams(tuple)
  }
}

@Entry
@Component
struct Router1 {

  build() {

    Column(){
      Column(){
        Text("我是页面1").fontSize(50)
      }
      Column(){

        Button("跳转")
          .onClick(()=>{
            router.pushUrl({
              url: 'pages/Router11',
              params: new routerParams('message' ,[123,456,789])
            })
          })
      }
    }
    .width('100%')
    .height('100%')
  }
}
import router from '@ohos.router';

class innerParams {
  array:number[]

  constructor(tuple:number[]) {
    this.array = tuple
  }
}

class routerParams {
  text:string
  data:innerParams
  constructor(str:string, tuple:number[]) {
    this.text = str
    this.data = new innerParams(tuple)
  }
}

@Entry
@Component
struct Router11 {

  aboutToAppear(): void {
    let s:number[]=((router.getParams() as routerParams).data as innerParams).array
    console.log("*********:"+s);
  }
  build() {
    Column(){
      Text("123").fontSize(50)
      Row(){
        Text("33333").fontSize(50)
      }
    }
    .width('100%')
    .height('100%')
    .opacity(0.5)
    .backgroundColor(Color.Pink)

  }
}
分享
微博
QQ
微信
回复
2024-12-18 17:12:53
相关问题
HarmonyOS 组件接收页面参数
434浏览 • 1回复 待解决
HarmonyOS 页面接收参数报错
211浏览 • 1回复 待解决
HarmonyOS router.back返回参数如何接收
301浏览 • 1回复 待解决
HarmonyOS 路由跳转怎么接收参数
407浏览 • 1回复 待解决
HarmonyOS 路由页面接收回传参数方式
1588浏览 • 1回复 待解决
HarmonyOS 路由参数如何接收
660浏览 • 1回复 待解决
返回页面router.back如何传递参数
1224浏览 • 2回复 待解决