HarmonyOS 在使用router.pushUrl({url: url, params: params})进行页面间传递数据时无法接收map类型参数

HarmonyOS
2024-12-18 15:34:08
1928浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
put_get

router不支持map类型的数据传参,params中只能包含基础类型的数据.可以使用Record代替map

private routerParams : RouterParams = new RouterParams()
private param : Record<string, string> = {};
routePage() {
  try {
    this.param['vip_source'] = 'qww'
    this.routerParams.pageType = '11'
    this.routerParams.params = this.param
    this.routerParams.title = '新闻'
    router.pushUrl({
      url: 'pages/RouterA',
      params: this.routerParams
    })
  } catch (err) {
    console.info(` fail callback, code: ${err.code}, msg: ${err.msg}`)
  }
}

@State value:Record<string, Record<string,string>> = router.getParams() as Record<string, Record<string,string>>;

onPageShow() {
  console.log("hh2:" + this.value['title'])
  console.log("hh3:" + this.value['params']['vip_source'])
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
分享
微博
QQ
微信
回复
2024-12-18 17:55:17


相关问题
router.pushUrl 无法使用Map类型参数
1028浏览 • 1回复 待解决
router.pushUrl是否无法使用Map类型参数
1439浏览 • 1回复 待解决
同一个HSP中,router.pushUrl中的url问题
1223浏览 • 1回复 待解决
HarmonyOS router.pushUrl使用基于Har
794浏览 • 1回复 待解决
HarmonyOS router.pushUrl跳转报100002
1395浏览 • 1回复 待解决
router路由中的params对象
950浏览 • 1回复 待解决
HarmonyOS router参数不能是map类型
728浏览 • 1回复 待解决