参考demo:@Component struct CustomContainer { @Prop header: string = ''; @Builder defaultBulder(){} @BuilderParam rightBuilder: () => void = this.defaultBulder build() { Column() { this.rightBuilder() } } } @Entry @Component struct CustomContainerUser { @State text: string = 'header'; build() { Column() { Text(this.text) CustomContainer({ header: this.text }) { Column() { this.rightBuilder('testA', 'testB') }.backgroundColor(Color.Yellow) .onClick(() => { this.text = 'changeHeader'; }) } } } @Builder rightBuilder(label1: string, label2: string) { Column() { Button('右边按钮').onClick(() => { this.text = '点击了' console.log('qqqq1=',this) }) // } } } }
参考demo: