创建一个登录界面
创建登录源代码
@Entry @Component struct SevenPage{ @State userName:string = ""; @State passWorld:string = ""; build() { Column() { Row() { Text("账号:").fontSize(22).width('20%') TextInput({ placeholder: "请输入账号" ,text:this.userName}).fontSize(26) .onChange((EnterKeyType)=>{ this.userName = EnterKeyType; }).width('80%') } Blank() Row() { Text("密码:").fontSize(22).width('20%') TextInput({ placeholder: "请输入密码" ,text:this.passWorld}) .type(InputType.Password).fontSize(26) .onChange((EnterKeyType)=>{ this.passWorld = EnterKeyType; }).width('80%') } Blank() Row(){ Button("登录").width('80%').onClick(()=>{ if(this.userName == "admin" && this.passWorld == "admin"){ console.log("登录测试成功"); }else{ console.log("账号密码有误"); } }) } }.width('100%').height('30%') .justifyContent(FlexAlign.Center) .margin({top:100}) } } 我们设置登录用户名:admin 密码:admin
测试效果
正确的用户名和密码 
错误的


