未验证 提交 a1ec7e7b 编写于 作者: O openharmony_ci 提交者: Gitee

!22782 BuilderParam添加bind(this)说明

Merge pull request !22782 from houhaoyu/cherry-pick-1692773946
......@@ -63,7 +63,7 @@
- 需注意this指向正确。
以下示例中,Parent组件在调用this.componentBuilder()时,this.label指向其所属组件,即“Parent”。\@Builder componentBuilder()传给子组件\@BuilderParam aBuilder0,在Child组件中调用this.aBuilder0()时,this.label指向在Child的label,即“Child”。
以下示例中,Parent组件在调用this.componentBuilder()时,this.label指向其所属组件,即“Parent”。\@Builder componentBuilder()传给子组件\@BuilderParam aBuilder0,在Child组件中调用this.aBuilder0()时,this.label指向在Child的label,即“Child”。对于\@BuilderParam aBuilder1,在将this.componentBuilder传给aBuilder1时,调用bind绑定了this,因此其this.label指向Parent的label。
> **说明:**
>
......@@ -74,10 +74,12 @@
struct Child {
label: string = `Child`
@BuilderParam aBuilder0: () => void;
@BuilderParam aBuilder1: () => void;
build() {
Column() {
this.aBuilder0()
this.aBuilder1()
}
}
}
......@@ -94,7 +96,7 @@
build() {
Column() {
this.componentBuilder()
Child({ aBuilder0: this.componentBuilder })
Child({ aBuilder0: this.componentBuilder, aBuilder1: this.componentBuilder.bind(this) })
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册