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

Checkbox

$$语法,$$绑定的变量发生变化时,会触发UI的刷新

@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)
  }
}

Search

@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)
  }
}

​​​​​​​ 

TextInput

@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)
  }
}

还有很多组件都支持双向绑定

相关推荐

  1. vue3组件数据双向

    2024-03-17 22:34:03       53 阅读
  2. 如果reactive数据没有双向

    2024-03-17 22:34:03       54 阅读
  3. Vue双向数据原理

    2024-03-17 22:34:03       62 阅读
  4. C# winform双向数据

    2024-03-17 22:34:03       41 阅读
  5. Vue 双向数据

    2024-03-17 22:34:03       40 阅读
  6. Vue双向数据原理

    2024-03-17 22:34:03       54 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-17 22:34:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-17 22:34:03       100 阅读
  3. 在Django里面运行非项目文件

    2024-03-17 22:34:03       82 阅读
  4. Python语言-面向对象

    2024-03-17 22:34:03       91 阅读

热门阅读

  1. C语言经典面试题目(十二)

    2024-03-17 22:34:03       42 阅读
  2. python类对象

    2024-03-17 22:34:03       36 阅读
  3. 对springboot json模块的BasicJsonParser类进行注释学习

    2024-03-17 22:34:03       41 阅读
  4. 获得1688中国站获得工厂档案信息 API

    2024-03-17 22:34:03       36 阅读
  5. linux下的进程间通信

    2024-03-17 22:34:03       37 阅读
  6. Python中的变量是什么类型?

    2024-03-17 22:34:03       40 阅读
  7. Mysql 表设计范式

    2024-03-17 22:34:03       43 阅读
  8. PyTorch学习笔记之激活函数篇(五)

    2024-03-17 22:34:03       46 阅读
  9. C/C++蓝桥杯之杨辉三角

    2024-03-17 22:34:03       42 阅读
  10. MySQL 中的自增ID及其应用场景

    2024-03-17 22:34:03       40 阅读
  11. C语言学习笔记day7

    2024-03-17 22:34:03       40 阅读
  12. 人工智能的发展与未来

    2024-03-17 22:34:03       50 阅读
  13. git |常用命令

    2024-03-17 22:34:03       44 阅读