鸿蒙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·网络
mmoyula1 分钟前
【RK3568 驱动开发:实现一个最基础的网络设备】
android·linux·驱动开发
weixin_478689769 分钟前
操作系统【2】【内存管理】【虚拟内存】【参考小林code】
数据库·nosql
今天背单词了吗98018 分钟前
算法学习笔记:8.Bellman-Ford 算法——从原理到实战,涵盖 LeetCode 与考研 408 例题
java·开发语言·后端·算法·最短路径问题
天天摸鱼的java工程师20 分钟前
使用 Spring Boot 整合高德地图实现路线规划功能
java·后端
阿杆22 分钟前
😡同事查日志太慢,我现场教他一套 grep 组合拳!
linux·后端
墨小傲34 分钟前
基于Linux下的vscode c/c++开发环境搭建详细教程
linux·c语言·vscode
东阳马生架构36 分钟前
订单初版—2.生单链路中的技术问题说明文档
java
cui_win40 分钟前
【网络】Linux 内核优化实战 - net.ipv4.tcp_timestamps
linux·网络·tcp/ip
czhc114007566341 分钟前
Linux 77 FTP
linux·运维·服务器