中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
微信扫码分享
没想到有人有跟我一样的需求呢,我刚写过类似的案例,给博主参考一下 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') } }