鸿蒙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)

相关推荐
取加若则_1 小时前
Linux进程调度:双队列高效管理
linux·算法
Louis Maos3 小时前
堆与栈分配的本质区别
java·开发语言
赵渝强老师3 小时前
【赵渝强老师】国产金仓数据库的表空间
数据库·postgresql
人道领域3 小时前
【零基础学java】(HashMap源码解析--添加第一个元素)
java·哈希算法·散列表
chenyuhao20243 小时前
Linux网络编程:TCP协议
linux·运维·服务器·网络协议·tcp/ip·udp·tcp
毕设源码-朱学姐4 小时前
【开题答辩全过程】以 果蔬禽蛋生鲜食品采购配送系统的设计与实现为例,包含答辩的问题和答案
java·开发语言
廋到被风吹走4 小时前
【数据库】【Oracle】PL/SQL 存储过程与函数
数据库·sql·oracle
hweiyu004 小时前
Linux 命令:xz
linux·运维·服务器
zfj3214 小时前
java线程的不同状态下调用interrupt()方法后的行为及注意事项
java·开发语言·interrupt·线程中断·线程状态
amao99884 小时前
数据库原理与技术 - 3-3 3-4 SQL语言(二)数据操作语言
数据库·sql·oracle