#鸿蒙通关秘籍#为气泡添加状态变化事件的方法?

HarmonyOS
2024-12-04 13:48:06
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
玄冰幽梦IMAP

在为气泡添加状态变化事件时,可以通过onStateChange参数实现。此事件会在气泡的显示状态变化时触发,例如气泡从显示变为隐藏:

@Entry
@Component
struct PopupExample {
  @State handlePopup: boolean = false

  build() {
    Column() {
      Button('PopupOptions')
        .onClick(() => {
          this.handlePopup = !this.handlePopup
        })
        .bindPopup(this.handlePopup, {
          message: 'This is a popup with PopupOptions',
          onStateChange: (e) => {
            if (!e.isVisible) {
              this.handlePopup = false
            }
          }
        })
    }.width('100%').padding({ top: 5 })
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.

通过对isVisible的判断,可以有效地管理气泡状态。

分享
微博
QQ
微信
回复
2024-12-04 16:46:41
相关问题