在HarmonyOS NEXT开发中想在builder中插入builder?

在HarmonyOS NEXT开发中想在builder中插入builder?

阅读 1.2k
1 个回答

请参考以下文档:https://gitee.com/openharmony/docs/blob/master/zh-cn/applicat...
并参考以下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.") 
      } 
    }) 
  } 
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进