news 2026/6/26 21:57:08

路由---页面切换

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
路由---页面切换

本次一共需要三个页面切换 需要写出三个文件

实例代码1:

import router from '@ohos.router'; @Entry @Component struct meng{ @State username:string ="" @State password:string ="" @State password2:string ="" build() { Column({space:25}){ Image($r('app.media.cxstudy_1781085599889')) .width(120) .height(120) .borderRadius(60) Text("注册") .fontSize(32) .fontWeight(FontWeight.Bolder) Row(){ Text("账号") .fontSize(26) .width('40%') .textAlign(TextAlign.Center) TextInput({text:this.username}) .width('60%') .height(50) .onChange((value:string)=>{ this.username =value }) } Row(){ Text("密码") .fontSize(26) .width('40%') .textAlign(TextAlign.Center) TextInput({text:this.password}) .width('60%') .height(50) .type(InputType.Password) .onChange((value:string)=>{ this.password =value }) } Row(){ Text("确认密码") .fontSize(26) .width('40%') .textAlign(TextAlign.Center) TextInput({text:this.password2}) .width('60%') .height(50) .type(InputType.Password) .onChange((value:string)=>{ this.password2 =value }) } Text("已有账号,立即登录") .fontSize(22) .fontColor(0xababab) .onClick(()=>{ router.pushUrl({ url:"pages/Home" }) }) Button("立即注册") .width('100%') .height(50) .fontSize(24) .onClick(()=>{ if ((this.username!="")&&(this.password2!="")&&(this.password==this.password2)){ router.pushUrl({ url: "pages/yuyuyu" }) } else{ AlertDialog.show({ title:"注册失败", message:'注册的两次密码为空或者不一致,${this.username}' }) } }) } .width('100%') .height('100%') .padding(15) } }

实例代码2:

import router from '@ohos.router'; @Entry @Component struct yuyuyu{ build() { Column({space:25}){ Image($r('app.media.cxstudy_1781085599889')) .width(120) .height(120) .borderRadius(60) Text("登 录") .fontSize(32) .fontWeight(FontWeight.Bold) Row({space:15}){ Text("账 号") .fontSize(26) TextInput() .width("70%") .height(50) } Row({space:15}){ Text("密 码") .fontSize(26) TextInput() .width("70%") .height(50) .type(InputType.Password) } Text("没有账号,立即注册") .fontSize(22) .fontColor(0xababab) .onClick(()=>{ router.pushUrl({ url:"pages/meng" }) }) Button("立 即 登 录") .width('100%') .height(50) .fontSize(24) .onClick(()=>{ router.pushUrl({ url:"pages/Home" }) }) } .width('100%') .height('100%') .padding(15) } }

实例代码3:

import router from '@ohos.router'; @Entry @Component struct HomePage { @State username: string = "" onPageShow(): void { const params = router.getParams() as Record<string, string> if (params) { this.username = params.username } } build() { Column() { Text(`你好 ${this.username}`) } } }

特别注意:需要在json文件添加本文件名

如图所示:

成果展示1:

成果展示2:

成果展示3:

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/6/26 21:56:34

100个RPG Maker MV插件:零代码打造专业级游戏体验

100个RPG Maker MV插件&#xff1a;零代码打造专业级游戏体验 【免费下载链接】RPGMakerMV RPGツクールMV、MZで動作するプラグインです。 项目地址: https://gitcode.com/gh_mirrors/rp/RPGMakerMV RPG Maker MV插件集是一个包含100多个专业插件的开源项目&#xff0c;…

作者头像 李华
网站建设 2026/6/26 21:54:50

大厂Agent架构我拆了三遍,发现一人公司只需要3个文件(附模板)

一句话&#xff1a;阿里云那篇Agent四层架构&#xff0c;我拆了三遍。花80%篇幅解决的是100人团队的协作问题。一人公司只需要那20%——3个文件&#xff0c;跑通一个项目链条。一、起因&#xff1a;一个独立开发朋友问我"要不要搭Agent架构" 事情是这样的。 上个月一…

作者头像 李华
网站建设 2026/6/26 21:54:42

源头厂家优势凸显!无锡百瑞德TIG热丝堆焊设备厂家实力解读

国内堆焊设备市场分为贴牌中间商、组装小厂、自研源头厂家三类业态&#xff0c;不同业态设备品质、技术实力、售后周期、定制能力差距悬殊。近些年大量制造企业反馈&#xff0c;采购贴牌堆焊设备后出现程序锁死、故障频发、非标无法改造、售后推诿、工艺无法升级等问题&#xf…

作者头像 李华
网站建设 2026/6/26 21:50:09

电动赛车BMS系统设计与LTC6813应用实践

1. 项目背景与核心需求太原工业学院纯电动方程式赛车项目中的电池箱采集总成&#xff0c;是整车能量管理系统的核心部件。作为参加过三届大学生方程式比赛的老队员&#xff0c;我深刻体会到这个看似简单的模块对整车性能的决定性影响。电池箱采集总成需要实时监控多达96节锂电池…

作者头像 李华
网站建设 2026/6/26 21:48:48

用友NC psnImage/download接口SQL注入漏洞复现与防御分析

1. 项目概述&#xff1a;一次典型的企业级应用漏洞深度剖析最近在整理一些历史漏洞的复现笔记&#xff0c;翻到了用友NC这个老牌ERP系统的一个经典案例——psnImage/download接口的SQL注入漏洞。这个漏洞本身并不复杂&#xff0c;但它的出现场景和利用方式&#xff0c;非常典型…

作者头像 李华
网站建设 2026/6/26 21:48:22

2026不想996?这些外企、券商的技术岗校招正在偷偷抢人

前几天一个读者给我发消息。 “学长&#xff0c;我拿了某大厂的测开offer&#xff0c;总包35万。但师兄说那边平均下班时间是晚上9点半&#xff0c;忙起来周末也得on call。有没有不那么卷的选择&#xff1f;钱少点也行。” 我给他列了几个方向——外资银行科技岗、头部券商Fin…

作者头像 李华