HarmonyOS 想在builder中插入builder

HarmonyOS
9h前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
FengTianYa

请参考以下文档:https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/quick-start/arkts-builderparam.md

并参考以下demo:

@Component
struct activeDialog {
  @Builder
  customBuilder() {
  }

  // 使用父组件@Builder装饰的方法初始化子组件@BuilderParam
  @BuilderParam customBuilderParam: () => void = this.customBuilder;

  build() {
    Column({ space: 5 }) {
      Text('9998888888')
      // this.customBuilderParam()
    }.width('100%').height('100%').justifyContent(FlexAlign.Center)
  }
}

@Entry
@Component
struct Parent {
  @State isShow: boolean = true
  @Builder
  componentBuilder() {
    Text(`Parent builder `)
  }

  build() {
    Column() {
      activeDialog({ customBuilderParam: this.componentBuilder })
    }
    .bindContentCover(this.isShow, this.componentBuilder(), {
      modalTransition: ModalTransition.NONE,
      // backgroundColor: 'rgba(0,0,0,0.5)',
      onAppear: () => {
        console.log("BindContentCover onAppear.")
      },
      onDisappear: () => {
        console.log("BindContentCover onDisappear.")
      }
    })
  }
}
分享
微博
QQ
微信
回复
7h前
相关问题
HarmonyOS 如何在builder函数传入组件
366浏览 • 0回复 待解决
@Extend、@Styles、@Builder 区别?
432浏览 • 1回复 待解决
HarmonyOS @Builder的内容如何刷新
8浏览 • 0回复 待解决
@Builder使用引用时异常
902浏览 • 1回复 待解决
@Builder自定义构建函数,如何回参?
304浏览 • 1回复 待解决