开源鸿蒙 Event Configuration

2022-08-09 浏览 (678)

Event Configuration

You can use event methods to configure events supported by components.

  • Example of using a lambda expression to configure the event of a component:

    // Counter is a private data variable defined in the component.
    Button('add counter')
        .onClick(() => {
            this.counter += 2
        })
    
  • When using an anonymous function expression to configure the event of a component, bind must be used to ensure that the contained components are referenced by this in the function body.

    // Counter is a private data variable defined in the component.
    Button('add counter')
        .onClick(function () {
            this.counter += 2
        }.bind(this))
    
  • Example of using a component's member function to configure the event of the component:

    myClickHandler(): void {
        // do something
    }
    
    ...
    
    Button('add counter')
      .onClick(this.myClickHandler)
    

你可能感兴趣的文章

开源鸿蒙 UI Development

开源鸿蒙 ArkUI Overview

开源鸿蒙 File Organization

开源鸿蒙 app.js

开源鸿蒙 “js” Tag

开源鸿蒙 Lifecycle

开源鸿蒙 Multi-Language Capability

开源鸿蒙 Resource Limitations and Access

开源鸿蒙 CSS

开源鸿蒙 HML

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/b0ce1ad29d0c4253ab2d6c42dba94374