未验证 提交 a679daf4 编写于 作者: 1 189******51 提交者: Gitee

IssueNo: #I7XEJ4:[新需求]: Rectify the arkts syntax of qs on monthly

Description: Rectify the arkts syntax of qs on monthly
Sig: SIG_ApplicaitonFramework
Feature or Bugfix: Feature
Binary Source: No
Signed-off-by: N189******51 <lipeicheng5@huawei.com>
上级 e8891743
......@@ -34,20 +34,24 @@
- 用父组件自定义构建函数初始化子组件\@BuildParam装饰的方法。
```ts
@Component
struct Child {
@BuilderParam aBuilder0: () => void;
@Component
struct Child {
@Builder componentBuilder() {
Text(`Parent builder `)
}
@BuilderParam aBuilder0: () => void = this.componentBuilder;
build() {
Column() {
this.aBuilder0()
}
}
}
}
@Entry
@Component
struct Parent {
@Entry
@Component
struct Parent {
@Builder componentBuilder() {
Text(`Parent builder `)
}
......@@ -57,7 +61,7 @@
Child({ aBuilder0: this.componentBuilder })
}
}
}
}
```
......@@ -70,11 +74,15 @@
> 开发者谨慎使用bind改变函数调用的上下文,可能会使this指向混乱。
```ts
@Component
struct Child {
@Component
struct Child {
@Builder componentBuilder() {
Text(`Child builder `)
}
label: string = `Child`
@BuilderParam aBuilder0: () => void;
@BuilderParam aBuilder1: () => void;
@BuilderParam aBuilder0: () => void = this.componentBuilder;
@BuilderParam aBuilder1: () => void = this.componentBuilder;
build() {
Column() {
......@@ -82,11 +90,11 @@
this.aBuilder1()
}
}
}
}
@Entry
@Component
struct Parent {
@Entry
@Component
struct Parent {
label: string = `Parent`
@Builder componentBuilder() {
......@@ -96,10 +104,10 @@
build() {
Column() {
this.componentBuilder()
Child({ aBuilder0: this.componentBuilder, aBuilder1: this.componentBuilder.bind(this) })
}
Child({ aBuilder0: this.componentBuilder, aBuilder1: this.componentBuilder })
}
}
}
```
......@@ -112,7 +120,11 @@
```ts
@Builder function GlobalBuilder1($$ : {label: string }) {
class GlobalBuilderParam {
label: string = ""
}
@Builder function GlobalBuilder1($$ : GlobalBuilderParam) {
Text($$.label)
.width(400)
.height(50)
......@@ -121,11 +133,15 @@
@Component
struct Child {
@Builder componentBuilder() {
Text(`Child builder `)
}
label: string = 'Child'
// 无参数类,指向的componentBuilder也是无参数类型
@BuilderParam aBuilder0: () => void;
@BuilderParam aBuilder0: () => void = this.componentBuilder;
// 有参数类型,指向的GlobalBuilder1也是有参数类型的方法
@BuilderParam aBuilder1: ($$ : { label : string}) => void;
@BuilderParam aBuilder1: ($$ : GlobalBuilderParam) => void = this.componentBuilder;
build() {
Column() {
......@@ -167,10 +183,17 @@ struct Parent {
```ts
// xxx.ets
class CustomContainerParam {
header: string = '';
}
@Component
struct CustomContainer {
@Prop header: string;
@BuilderParam closer: () => void
@Builder componentCloser() {
Text(`Custom closer `)
}
@Prop header: string = '';
@BuilderParam closer: () => void = this.componentCloser;
build() {
Column() {
......@@ -194,12 +217,15 @@ struct CustomContainer {
@Component
struct CustomContainerUser {
@State text: string = 'header';
param: CustomContainerParam = {
header: this.text
};
build() {
Column() {
// 创建CustomContainer,在创建CustomContainer时,通过其后紧跟一个大括号“{}”形成尾随闭包
// 作为传递给子组件CustomContainer @BuilderParam closer: () => void的参数
CustomContainer({ header: this.text }) {
CustomContainer(this.param) {
Column() {
specificParam('testA', 'testB')
}.backgroundColor(Color.Yellow)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册