Web前端之路ArkTS/ArkUI实战1024

51、鸿蒙/路由跳转带参数

2024-08-15  本文已影响0人  圆梦人生

路由跳转到一个只有页面没有UIAbility的模块:

案例

{
  "src": [
    "pages/Index",
    "pages/SubPag"  // 添加页面
  ]
}
import { router } from '@kit.ArkUI'
@Entry
@Component
struct Index {
  build(){
     Button('点击跳转页面').onClick((event: ClickEvent) => {
        router.pushUrl({
          url: 'pages/SubPag',
          params: {
            userName: 'zs'
          }
        })
      })
  }
}
import { router } from '@kit.ArkUI';
interface UserVO {
  userName: string;
}

@Entry
@Component
struct SubPag {
  @State message: string = 'Hello World';
  aboutToAppear(): void {
     let params = router.getParams() as UserVO;
      console.log('params参数 === ', JSON.stringify(params));
  }
  build() {
    Text('hello')
  }
}
上一篇下一篇

猜你喜欢

热点阅读