// 单个BuildParam
@Entry
@Component
struct ScrollDemo {
build () {
Column () {
SonCom () {
Button('直接传递进来')
}
}
}
}
@Component
struct SonCom {
// 定义BuildParam 接受外部传入的UI并设置默认值
@BuildParam ContentBuilder: () => void = this.defaultBuilder
@Builder
defaultBuilder() {
Text('默认的内容')
}
build () {
Column () {
// 使用 @BuildParam 装饰的成员变量
this.ContentBuilder();
}
}
}
// 多个BuildParam
@Entry
@Component
struct ScrollDemo {
@Builder
fTBuilder() {...}
@Builder
fCBuilder() {...}
build () {
Column () {
SonCom ({
tBuilder: this.fTBuilder,
cBuilder: this.fCBuilder
})
}
}
}
@Component
struct SonCom {
// 定义BuildParam 接受外部传入的UI并设置默认值
@BuildParam tBuilder: () => void = this.tDefaultBuilder
@BuildParam cBuilder: () => void = this.cDefaultBuilder
@Builder
tDefaultBuilder() {
Text('默认的内容')
}
@Builder
cDefaultBuilder() {
Text('默认的内容')
}
build () {
Column () {
// 使用 @BuildParam 装饰的成员变量
this.tBuilder();
this.cBuilder();
}
}
}
BuilderParam构建函数(和vue插槽很像)
最新推荐文章于 2024-09-05 20:31:37 发布