鸿蒙Next 支持数据双向绑定的组件:Checkbox--Search--TextInput

Checkbox

语法,$$绑定的变量发生变化时,会触发UI的刷新 ```javascript @Entry @Component struct MvvmCase { @State isMarry:boolean = false @State searchText:string = '' build() { Grid(){ GridItem(){ Column(){ Text("checkbox 的双向绑定") Checkbox() .select($$this.isMarry) Text(this.isMarry+"") Button('改变') .onClick(()=>{ this.isMarry=!this.isMarry }) } } .height(200) .backgroundColor(Color.Yellow) } .width('100%') .height('100%') .columnsTemplate("1fr 1fr") .columnsGap(20) .rowsGap(20) } } ``` ![](https://file.jishuzhan.net/article/1770739551564730370/43ca675c8e14472cb93ab61996b0400f.webp)![](https://file.jishuzhan.net/article/1770739551564730370/eab5dd4e8386e965fab4c25531e87585.webp) #### Search ![](https://file.jishuzhan.net/article/1770739551564730370/a597328db2eb81452a16d5d9f8381194.webp) ```javascript @Entry @Component struct MvvmCase { @State isMarry:boolean = false @State searchText:string = '' build() { Grid(){ GridItem(){ Column(){ Text("search 的双向绑定") Search({value:$$this.searchText}) Text(this.searchText+"") Button('改变') .onClick(()=>{ this.searchText='老宋你好' }) } } .height(200) .backgroundColor(Color.Pink) } .width('100%') .height('100%') .columnsTemplate("1fr 1fr") .columnsGap(20) .rowsGap(20) } } ``` ​​​​​​​![](https://file.jishuzhan.net/article/1770739551564730370/4fee6f0742e74fdc30860d4ce8e99f5c.webp) ![](https://file.jishuzhan.net/article/1770739551564730370/8be4fb59ce992e8c331ac5d9c9c2a639.webp) #### TextInput ![](https://file.jishuzhan.net/article/1770739551564730370/71a4263caae50583abb19bbb3d666f2a.webp) @Entry @Component struct MvvmCase { @State isMarry:boolean = false @State searchText:string = '' controller: TextInputController = new TextInputController() build() { Grid(){ GridItem(){ Column(){ Text("TextInput 的双向绑定") TextInput({ text: $$this.searchText, placeholder: 'TextInput 的双向绑定', controller: this.controller }) Text(this.searchText+"") Button('改变') .onClick(()=>{ this.searchText='老宋你好01' }) } } .height(200) .backgroundColor(Color.Pink) } .width('100%') .height('100%') .columnsTemplate("1fr 1fr") .columnsGap(20) .rowsGap(20) } } ![](https://file.jishuzhan.net/article/1770739551564730370/aeb1a1252f435d1db3d980a4a97b0c96.webp)![](https://file.jishuzhan.net/article/1770739551564730370/def7a3062abb85a538ed26f840a3b983.webp) 还有很多组件都支持双向绑定 ![](https://file.jishuzhan.net/article/1770739551564730370/a5b70bdf9fe8f127f084b10b7169045f.webp)

相关推荐
叽哥2 分钟前
Kotlin学习第 7 课:Kotlin 空安全:解决空指针问题的核心机制
android·java·kotlin
向上的车轮8 分钟前
如何用 Rust 重写 SQLite 数据库(二):是否有市场空间?
数据库·rust·sqlite
NiKo_W10 分钟前
Linux 开发工具(1)
linux·运维·服务器
jc062012 分钟前
4.2-中间件之MySQL
数据库·mysql
笑口常开xpr15 分钟前
Linux动静态库开发基础:静态库与动态库的编译构建、链接使用及问题排查
linux·c语言·动态库·静态库
guslegend16 分钟前
Java面试小册(3)
java
派葛穆18 分钟前
Unity-按钮实现场景跳转
java·unity·游戏引擎
弥巷18 分钟前
【Android】Viewpager2实现无限轮播图
java
虫小宝27 分钟前
返利app排行榜的缓存更新策略:基于过期时间与主动更新的混合方案
java·spring·缓存
SimonKing29 分钟前
告别繁琐配置!Retrofit-Spring-Boot-Starter让HTTP调用更优雅
java·后端·程序员