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

!23585 Rectify the arkts syntax of qs

Merge pull request !23585 from 189******51/master
...@@ -77,13 +77,22 @@ MyGlobalBuilderFunction() ...@@ -77,13 +77,22 @@ MyGlobalBuilderFunction()
```ts ```ts
ABuilder( $$ : { paramA1: string, paramB1 : string } ); class ABuilderParam {
paramA1: string = ''
paramB1: string = ''
}
ABuilder($$ : ABuilderParam);
``` ```
```ts ```ts
@Builder function ABuilder($$: { paramA1: string }) { class ABuilderParam {
paramA1: string = ''
}
@Builder function ABuilder($$: ABuilderParam) {
Row() { Row() {
Text(`UseStateVarByReference: ${$$.paramA1} `) Text(`UseStateVarByReference: ${$$.paramA1} `)
} }
...@@ -94,10 +103,10 @@ struct Parent { ...@@ -94,10 +103,10 @@ struct Parent {
@State label: string = 'Hello'; @State label: string = 'Hello';
build() { build() {
Column() { Column() {
// 在Parent组件中调用ABuilder的时候,将this.label引用传递给ABuilder // Pass the this.label reference to the ABuilder component when the ABuilder component is called in the Parent component.
ABuilder({ paramA1: this.label }) ABuilder({ paramA1: this.label })
Button('Click me').onClick(() => { Button('Click me').onClick(() => {
// 点击“Click me”后,UI从“Hello”刷新为“ArkUI” // After Click me is clicked, the UI text changes from Hello to ArkUI.
this.label = 'ArkUI'; this.label = 'ArkUI';
}) })
} }
......
...@@ -34,30 +34,34 @@ ...@@ -34,30 +34,34 @@
- 用父组件自定义构建函数初始化子组件\@BuildParam装饰的方法。 - 用父组件自定义构建函数初始化子组件\@BuildParam装饰的方法。
```ts ```ts
@Component @Component
struct Child { struct Child {
@BuilderParam aBuilder0: () => void; @Builder componentBuilder() {
Text(`Parent builder `)
}
build() { @BuilderParam aBuilder0: () => void = this.componentBuilder;
Column() {
this.aBuilder0() build() {
} Column() {
this.aBuilder0()
} }
} }
}
@Entry @Entry
@Component @Component
struct Parent { struct Parent {
@Builder componentBuilder() { @Builder componentBuilder() {
Text(`Parent builder `) Text(`Parent builder `)
} }
build() { build() {
Column() { Column() {
Child({ aBuilder0: this.componentBuilder }) Child({ aBuilder0: this.componentBuilder })
}
} }
} }
}
``` ```
...@@ -70,36 +74,40 @@ ...@@ -70,36 +74,40 @@
> 开发者谨慎使用bind改变函数调用的上下文,可能会使this指向混乱。 > 开发者谨慎使用bind改变函数调用的上下文,可能会使this指向混乱。
```ts ```ts
@Component @Component
struct Child { struct Child {
label: string = `Child` @Builder componentBuilder() {
@BuilderParam aBuilder0: () => void; Text(`Child builder `)
@BuilderParam aBuilder1: () => void;
build() {
Column() {
this.aBuilder0()
this.aBuilder1()
}
}
} }
@Entry label: string = `Child`
@Component @BuilderParam aBuilder0: () => void = this.componentBuilder;
struct Parent { @BuilderParam aBuilder1: () => void = this.componentBuilder;
label: string = `Parent`
@Builder componentBuilder() { build() {
Text(`${this.label}`) Column() {
this.aBuilder0()
this.aBuilder1()
} }
}
}
build() { @Entry
Column() { @Component
this.componentBuilder() struct Parent {
Child({ aBuilder0: this.componentBuilder, aBuilder1: this.componentBuilder.bind(this) }) label: string = `Parent`
}
@Builder componentBuilder() {
Text(`${this.label}`)
}
build() {
Column() {
this.componentBuilder()
Child({ aBuilder0: this.componentBuilder, aBuilder1: this.componentBuilder })
} }
} }
}
``` ```
...@@ -112,7 +120,11 @@ ...@@ -112,7 +120,11 @@
```ts ```ts
@Builder function GlobalBuilder1($$ : {label: string }) { class GlobalBuilderParam {
label: string = ""
}
@Builder function GlobalBuilder1($$ : GlobalBuilderParam) {
Text($$.label) Text($$.label)
.width(400) .width(400)
.height(50) .height(50)
...@@ -121,11 +133,15 @@ ...@@ -121,11 +133,15 @@
@Component @Component
struct Child { struct Child {
@Builder componentBuilder() {
Text(`Child builder `)
}
label: string = 'Child' label: string = 'Child'
// 无参数类,指向的componentBuilder也是无参数类型 // 无参数类,指向的componentBuilder也是无参数类型
@BuilderParam aBuilder0: () => void; @BuilderParam aBuilder0: () => void = this.componentBuilder;
// 有参数类型,指向的GlobalBuilder1也是有参数类型的方法 // 有参数类型,指向的GlobalBuilder1也是有参数类型的方法
@BuilderParam aBuilder1: ($$ : { label : string}) => void; @BuilderParam aBuilder1: ($$ : GlobalBuilderParam) => void = this.componentBuilder;
build() { build() {
Column() { Column() {
...@@ -167,10 +183,17 @@ struct Parent { ...@@ -167,10 +183,17 @@ struct Parent {
```ts ```ts
// xxx.ets // xxx.ets
class CustomContainerParam {
header: string = '';
}
@Component @Component
struct CustomContainer { struct CustomContainer {
@Prop header: string; @Builder componentCloser() {
@BuilderParam closer: () => void Text(`Custom closer `)
}
@Prop header: string = '';
@BuilderParam closer: () => void = this.componentCloser;
build() { build() {
Column() { Column() {
...@@ -194,12 +217,15 @@ struct CustomContainer { ...@@ -194,12 +217,15 @@ struct CustomContainer {
@Component @Component
struct CustomContainerUser { struct CustomContainerUser {
@State text: string = 'header'; @State text: string = 'header';
param: CustomContainerParam = {
header: this.text
};
build() { build() {
Column() { Column() {
// 创建CustomContainer,在创建CustomContainer时,通过其后紧跟一个大括号“{}”形成尾随闭包 // 创建CustomContainer,在创建CustomContainer时,通过其后紧跟一个大括号“{}”形成尾随闭包
// 作为传递给子组件CustomContainer @BuilderParam closer: () => void的参数 // 作为传递给子组件CustomContainer @BuilderParam closer: () => void的参数
CustomContainer({ header: this.text }) { CustomContainer(this.param) {
Column() { Column() {
specificParam('testA', 'testB') specificParam('testA', 'testB')
}.backgroundColor(Color.Yellow) }.backgroundColor(Color.Yellow)
......
...@@ -42,15 +42,23 @@ HelloComponent可以在其他自定义组件中的build()函数中多次创建 ...@@ -42,15 +42,23 @@ HelloComponent可以在其他自定义组件中的build()函数中多次创建
```ts ```ts
class HelloComponentParam {
message: string = ""
}
@Entry @Entry
@Component @Component
struct ParentComponent { struct ParentComponent {
param: HelloComponentParam = {
message: 'Hello, World!'
}
build() { build() {
Column() { Column() {
Text('ArkUI message') Text('ArkUI message')
HelloComponent({ message: 'Hello, World!' }); HelloComponent(param);
Divider() Divider()
HelloComponent({ message: '你好!' }); HelloComponent(param);
} }
} }
} }
......
...@@ -81,7 +81,7 @@ ...@@ -81,7 +81,7 @@
build() { build() {
Row({ space: 10 }) { Row({ space: 10 }) {
Text(`${this.label}`) Text(`${this.label}`)
.makeMeClick(this.onClickHandler.bind(this)) .makeMeClick(this.onClickHandler)
} }
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册