#鸿蒙通关秘籍#一个组件上如何挂载多个bindSheet弹窗?

HarmonyOS
2024-12-11 10:15:32
1037浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
HDD梦蝶翼

没想到有人有跟我一样的需求呢,我刚写过类似的案例,给博主参考一下

enum BindType {
  Null,
  Type1,
  Type2,
  Type3
}

@Entry
@Component
struct TestPage {
  @State isShowBind: boolean = false
  @State bindType: BindType = BindType.Null

  build() {
    Column() {
      Button('bind1').onClick(() => {
        this.bindType = `BindType.Type1`
        this.isShowBind = true
      })

      Button('bind2').onClick(() => {
        this.bindType = `BindType.Type2`
        this.isShowBind = true
      })

      Button('bind3').onClick(() => {
        this.bindType = `BindType.Type3`
        this.isShowBind = true
      })
    }
    .width('100%')
    .height('100%')
    .bindSheet(`$$this.isShowBind`, this.bindBuilder())
  }

  @Builder
  bindBuilder() {
    Column() {
      if (this.bindType == `BindType.Type1`) {
        this.bindSheetBuilder1();
      } else if (this.bindType == `BindType.Type2`) {
        this.bindSheetBuilder2();
      } else if (this.bindType == `BindType.Type3`) {
        this.bindSheetBuilder3();
      }
    }
  }

  @Builder
  bindSheetBuilder1() {
    Text('1')
  }

  @Builder
  bindSheetBuilder2() {
    Text('2')
  }

  @Builder
  bindSheetBuilder3() {
    Text('3')
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
已于2024-12-17 16:07:06修改
分享
微博
QQ
微信
回复
2024-12-11 11:35:09
相关问题
HarmonyOS BindSheet再弹出一个Sheet
614浏览 • 1回复 待解决
ArkTS如何实现一个底部弹窗
1807浏览 • 1回复 待解决