登录页面跳转

📅 2026/6/26 19:51:31
登录页面跳转
创建两个文件第一个文件可以跳转到第二个文件 LoginRouter文件 import router from ohos.router; Entry Component struct LoginRouter{ State username:string 1 State password:string 1 build() { Column({space:30}){ Text(登录) .fontSize(32) .fontWeight(FontWeight.Bolder) TextInput({placeholder:请输入账号}) .width(100%) .height(50) .onChange((value:string){ this.username value }) TextInput({placeholder:请输入密码}) .width(100%) .height(50) .onChange((value:string){ this.password value }) Button(登录) .height(50) .width(100%) .fontSize(22) .onClick(() { if (this.username! this.password !){ router.pushUrl({ url:pages/HomePage, params:{ username:this.username, password:this.password } }) } else { AlertDialog.show({ title:登录失败, message:用户名或者密码不能为空 }) } }) } .width(100%) .height(100%) } }HomePage文件import router from ohos.router; Entry Component struct HomePage{ State name:string onPageShow(): void { const params router.getParams() as Recordstring,string if (params){ this.name params.username } } build() { Column(){ Text( 这是一个登陆后的页面) } } }