鸿蒙双向绑定组件:TextArea、TextInput、Search、Checkbox,文本输入组件,图案解锁组件PatternLock

对象暂不支持双向绑定,

效果:

代码:

复制代码
@Entry
@Component
struct MvvmCase {
  @State
  isSelect: boolean = false
  @State
  searchText: String = ""
  @State
  inputText: string = ""
  @State
  areaText: string = ""

  build() {

    Grid() {
      GridItem() {
        Column() {
          Text("checkbox的双向绑定")
          Checkbox()
            .select($$this.isSelect) //双向绑定,不支持对象双向绑定
          Text("选中状态:" + this.isSelect)
          Button("改变选中状态")
            .onClick(() => {
              this.isSelect = !this.isSelect
            })
        }
      }
      .height(200)
      .backgroundColor(Color.Pink)

      GridItem() {
        Column() {

          Text("Search的双向绑定")

          Search({ value: $$this.searchText })
          Text("数据内容:" + this.searchText)
          Button("改变选中状态")
            .onClick(() => {
              this.searchText = "改值"
            })
        }
      }
      .height(200)
      .backgroundColor(Color.Pink)

      GridItem() {
        Column() {
          Text("TextInput的双向绑定")
          TextInput({ text: $$this.inputText })
          Text("数据内容:" + this.inputText)
          Button("改值")
            .onClick(() => {
              this.inputText = "改值"
            })
        }
      }
      .height(200)
      .backgroundColor(Color.Pink)

      GridItem() {
        Column() {
          Text("TextArea的双向绑定")
          TextArea({ text: $$this.areaText})
            .maxLength(5)//最大长度
          Text("数据内容:" + this.areaText)
          Button("改值")
            .onClick(() => {
              this.areaText = "改值"
            })
        }
      }
      .height(200)
      .backgroundColor(Color.Pink)

      GridItem(){
        PatternLock()//图案解锁
      }
    }
    .columnsTemplate("1fr 1fr")
    .columnsGap(20)
    .rowsGap(20)
  }
}
相关推荐
THe CHallEnge of THe BrAve13 分钟前
anaconda3/conda依赖安装、环境配置、关联指定python版本
开发语言·python·conda
biomooc23 分钟前
R语言 | 2d概率密度分布图
开发语言·r语言
C666688826 分钟前
C#二叉树
开发语言·c#
zc.z1 小时前
Windows版-RabbitMQ自动化部署
开发语言·后端
爱喝热水的呀哈喽1 小时前
Java输入输出流与编码
开发语言·python
懒羊羊不进村1 小时前
Python基础——Matplotlib库
开发语言·python·matplotlib
钢铁男儿2 小时前
Python 字典和集合(字典的变种)
开发语言·python
晨辰丷3 小时前
【STL】list介绍(附与vector的比较)
c语言·开发语言·数据结构·c++·list
lisw053 小时前
2025年Python的主要应用场景
开发语言·python
懒羊羊不进村3 小时前
Python基础——Pandas库
开发语言·python·pandas