鸿蒙 next 5.0 版本页面跳转传参 && 接受参数 ,,接受的时候 要先定义接受参数的类型, 代码可以直接CV使用 [教程]
创始人
2024-11-10 23:12:14
0

1, 先看效果

2, 先准备好两个页面

index 页面 传递参数

import router from '@ohos.router'  @Entry @Component struct Index {    @State   list: string[] = ['星期一', '星期二','星期三', '星期四','星期五']    @State   activeIndex: number = 0    build() {     Row() {       Column({ space: 10 }) {         ForEach(this.list, (item: string, index: number) => {           Text(item)             .width('100%')             .height(50)             .textAlign(TextAlign.Center)             .fontSize(16)             .backgroundColor(this.activeIndex === index ? Color.White : Color.Orange)             .onClick(()=>{               this.activeIndex = index               console.log('111',this.activeIndex)             })         })         Row(){           Text('跳转传参')             .onClick(()=>{               router.pushUrl({                 url:'pages/one',                 params: {value:'test'}               })             })         }       }       .width(90)     }     .padding(15)     .backgroundColor(Color.Pink)     .width('100%')     .alignItems(VerticalAlign.Center)   } }

3, 接受参数

import router from '@ohos.router' import promptAction from '@ohos.promptAction'  // 声明接受参数的类型 interface PARAMS {   value: string }  @Entry @Component struct one {    @State    paramsValue: PARAMS = {     value: ''   }    aboutToAppear() {     // as 转换一下变成我们要接受的类型     this.paramsValue = router.getParams() as PARAMS      // 控制台打印     console.log(`111, ${JSON.stringify(this.paramsValue)}`)      // 提示传过来的内容     promptAction.showToast({message: this.paramsValue.value})   }    build() {     Column(){       Text('55555555555')        // 显示传的参数内容       Text(this.paramsValue.value)      }     .width('100%')     .height('100%')     .justifyContent(FlexAlign.Center)   } }

相关内容

热门资讯

玩家必看教程!!微信小程序免费... 玩家必看教程!!微信小程序免费黑科技(外挂),微信小程序怎么开挂切实有挂工具1、在微信小程序免费黑科...
一分钟教你!微信小程序黑科技(... 一分钟教你!微信小程序黑科技(外挂),微乐小程序黑科技下载都是有挂详细1)微信小程序黑科技有没有挂:...
每日必看!微乐小程序免费黑科技... 每日必看!微乐小程序免费黑科技(外挂),广西微乐小程序控制器确实今日头条1、玩家可以在微乐小程序免费...
终于知道!!微乐小程序黑科技(... 终于知道!!微乐小程序黑科技(外挂),贵州微乐自建房辅助软件下载其实有挂辅助1、实时微乐小程序黑科技...
解谜透视!红龙poker辅助器... 解谜透视!红龙poker辅助器免费观看,epoker透视底牌(透视)都是存在有辅助攻略(哔哩哔哩)1...
最终!WePOker有没有透视... 最终!WePOker有没有透视方法,传送屋辅助器(免费),本来真的是有辅助攻略(哔哩哔哩)1、玩家可...
透视课程!wepoker可以免... 透视课程!wepoker可以免费玩吗(透视)切实有辅助安装(哔哩哔哩)透视课程!wepoker可以免...
分辨真假!微信小程序黑科技(外... 分辨真假!微信小程序黑科技(外挂),微乐小程序怎么挂脚本都是有挂辅助1、首先打开微信小程序黑科技辅助...
科普透视!newpoker脚本... 科普透视!newpoker脚本,sohoo竞技联盟辅助器(透视)果然真的是有辅助攻略(哔哩哔哩)1、...
透视方针!如何判断wpk辅助软... 透视方针!如何判断wpk辅助软件的真假(透视)果然存在有辅助下载(哔哩哔哩)1、很好的工具软件,可以...