HarmonyOS 父组件中的builder里面的怎么根据父组件的@state的值来改变。

HarmonyOS
2天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
put_get

开发者可参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/arkts-builderparam-0000001820999553

示例demo:

@Component
struct Child {
  label: string = `Child`
  @Builder customBuilder() {}
  @Builder customChangeThisBuilder() {}
  @BuilderParam customBuilderParam: () => void = this.customBuilder;
  @BuilderParam customChangeThisBuilderParam: () => void = this.customChangeThisBuilder;

  build() {
    Column() {
      this.customBuilderParam()
      this.customChangeThisBuilderParam()
    }
  }
}

@Entry
@Component
struct Parent {
  @State label: string = `Parent`

  @Builder componentBuilder() {
    Text(`${this.label}`)
      .onClick(()=>{
        this.label='AAAAA'
      })
  }

  build() {
    Column() {
      this.componentBuilder()
      Child({ customBuilderParam: this.componentBuilder, customChangeThisBuilderParam: ():void=>{this.componentBuilder()} })
    }
  }
}
分享
微博
QQ
微信
回复
2天前
相关问题
组件调用子组件方法
1262浏览 • 1回复 待解决
组件调用组件方法
310浏览 • 1回复 待解决
组件事件可以传到组件
676浏览 • 1回复 待解决
设置子组件宽度不超出组件
612浏览 • 1回复 待解决