文档管理中心
我的
您当前正在浏览新版开发者文档中心,目录分类和层级有所调整。点击左侧当前文档分类名称前的“☰”图标,可切换文档分类。 了解新版目录
指南与API参考指南应用框架ArkUI(方舟UI框架)UI开发 (ArkTS声明式开发范式)学习UI范式基本语法组件扩展@BuilderParam装饰器:引用@Builder函数

@BuilderParam装饰器:引用@Builder函数

当开发者创建自定义组件并需要为其添加特定功能(例如Navigation功能)时,如果直接在组件内嵌入事件方法,会导致所有该自定义组件的实例都增加此功能。为了解决此问题,ArkUI引入了@BuilderParam装饰器。@BuilderParam用于装饰指向@Builder方法的变量,开发者可以在初始化自定义组件时,使用不同的方式(如参数修改、尾随闭包、借用箭头函数等)对@BuilderParam装饰的自定义构建函数进行传参赋值。在自定义组件内部,通过调用@BuilderParam为组件增加特定功能。

在阅读本文档前,建议提前阅读:@Builder。

说明

从API version 7开始支持。

从API version 9开始,该装饰器支持在ArkTS卡片中使用。

从API version 11开始,该装饰器支持在元服务中使用。

装饰器使用说明

初始化@BuilderParam装饰的方法

@BuilderParam装饰的方法只能被自定义构建函数(@Builder装饰的方法)初始化。

  • 使用所属自定义组件的自定义构建函数或者全局的自定义构建函数,在本地初始化@BuilderParam装饰的方法。

    收起
    自动换行
    深色代码主题
    复制
    1. @Builder
    2. function overBuilder() {
    3. }
    4. @Component
    5. struct Child {
    6. @Builder
    7. doNothingBuilder() {
    8. }
    9. // 使用自定义组件的自定义构建函数初始化@BuilderParam装饰的方法
    10. @BuilderParam customBuilderParam: () => void = this.doNothingBuilder;
    11. // 使用全局自定义构建函数初始化@BuilderParam装饰的方法
    12. @BuilderParam customOverBuilderParam: () => void = overBuilder;
    13. build() {
    14. }
    15. }
  • 使用父组件自定义构建函数初始化子组件@BuilderParam装饰的方法。

    收起
    自动换行
    深色代码主题
    复制
    1. @Component
    2. struct Child {
    3. @Builder
    4. customBuilder() {
    5. }
    6. @BuilderParam customBuilderParam: () => void = this.customBuilder;
    7. build() {
    8. Column() {
    9. this.customBuilderParam()
    10. }
    11. }
    12. }
    13. @Entry
    14. @Component
    15. struct Parent {
    16. @Builder
    17. componentBuilder() {
    18. Text('Parent builder')
    19. }
    20. build() {
    21. Column() {
    22. // 使用父组件自定义构建函数初始化子组件@BuilderParam装饰的方法
    23. Child({ customBuilderParam: this.componentBuilder })
    24. }
    25. }
    26. }

示例效果图

  • 需要注意this的指向。

    示例如下:

    收起
    自动换行
    深色代码主题
    复制
    1. @Component
    2. struct Child {
    3. label: string = 'Child';
    4. @Builder
    5. customBuilder() {
    6. }
    7. @Builder
    8. customChangeThisBuilder() {
    9. }
    10. @BuilderParam customBuilderParam: () => void = this.customBuilder;
    11. @BuilderParam customChangeThisBuilderParam: () => void = this.customChangeThisBuilder;
    12. build() {
    13. Column() {
    14. this.customBuilderParam()
    15. this.customChangeThisBuilderParam()
    16. }
    17. }
    18. }
    19. @Entry
    20. @Component
    21. struct Parent {
    22. label: string = 'Parent';
    23. @Builder
    24. componentBuilder() {
    25. Text(`${this.label}`)
    26. }
    27. build() {
    28. Column() {
    29. // 调用this.componentBuilder()时,this指向当前@Entry所装饰的Parent组件,即label变量的值为'Parent'。
    30. this.componentBuilder()
    31. Child({
    32. // 把this.componentBuilder传给子组件Child的@BuilderParam customBuilderParam,this指向的是子组件Child,即label变量的值为'Child'。
    33. customBuilderParam: this.componentBuilder,
    34. // 把():void=>{this.componentBuilder()}传给子组件Child的@BuilderParam customChangeThisBuilderParam,
    35. // 因为箭头函数的this指向的是宿主对象,所以label变量的值为'Parent'。
    36. customChangeThisBuilderParam: (): void => {
    37. this.componentBuilder()
    38. }
    39. })
    40. }
    41. }
    42. }

示例效果图

限制条件

使用场景

参数初始化组件

@BuilderParam装饰的方法为有参数或无参数的形式,必须与指向的@Builder方法类型匹配。

收起
自动换行
深色代码主题
复制
  1. class Tmp {
  2. public label: string = '';
  3. }
  4. @Builder
  5. function overBuilder($$: Tmp) {
  6. Text($$.label)
  7. .width('100%')
  8. .height(50)
  9. .backgroundColor(Color.Green)
  10. }
  11. @Component
  12. struct Child {
  13. label: string = 'Child';
  14. @Builder
  15. customBuilder() {
  16. }
  17. // 无参数类型,指向的customBuilder也是无参数类型
  18. @BuilderParam customBuilderParam: () => void = this.customBuilder;
  19. // 有参数类型,指向的overBuilder也是有参数类型的方法
  20. @BuilderParam customOverBuilderParam: ($$: Tmp) => void = overBuilder;
  21. build() {
  22. Column() {
  23. this.customBuilderParam()
  24. this.customOverBuilderParam({ label: 'global Builder label' })
  25. }
  26. }
  27. }
  28. @Entry
  29. @Component
  30. struct Parent {
  31. label: string = 'Parent';
  32. @Builder
  33. componentBuilder() {
  34. Text(`${this.label}`)
  35. }
  36. build() {
  37. Column() {
  38. this.componentBuilder()
  39. Child({ customBuilderParam: this.componentBuilder, customOverBuilderParam: overBuilder })
  40. }
  41. }
  42. }

示例效果图

尾随闭包初始化组件

在自定义组件中,使用@BuilderParam装饰的属性可通过尾随闭包进行初始化。初始化时,组件后需紧跟一个大括号“{}”形成尾随闭包场景。

说明
  • 此场景下自定义组件内仅有一个使用@BuilderParam装饰的属性。

  • 此场景下自定义组件不支持通用属性。

开发者可将尾随闭包内的内容看作@Builder装饰的函数传给@BuilderParam。

示例1:

收起
自动换行
深色代码主题
复制
  1. @Component
  2. struct CustomContainer {
  3. @Prop header: string = '';
  4. @Builder
  5. closerBuilder() {
  6. }
  7. // 使用父组件的尾随闭包{}(@Builder装饰的方法)初始化子组件@BuilderParam装饰的方法
  8. @BuilderParam closer: () => void = this.closerBuilder;
  9. build() {
  10. Column() {
  11. Text(this.header)
  12. .fontSize(30)
  13. this.closer()
  14. }
  15. }
  16. }
  17. @Builder
  18. function specificParam(label1: string, label2: string) {
  19. Column() {
  20. Text(label1)
  21. .fontSize(30)
  22. Text(label2)
  23. .fontSize(30)
  24. }
  25. }
  26. @Entry
  27. @Component
  28. struct CustomContainerUser {
  29. @State text: string = 'header';
  30. build() {
  31. Column() {
  32. // 创建CustomContainer,在创建CustomContainer时,通过其后紧跟一个大括号“{}”形成尾随闭包
  33. // 作为传递给子组件CustomContainer @BuilderParam closer: () => void的参数
  34. CustomContainer({ header: this.text }) {
  35. Column() {
  36. specificParam('testA', 'testB')
  37. }.backgroundColor(Color.Yellow)
  38. .onClick(() => {
  39. this.text = 'changeHeader';
  40. })
  41. }
  42. }
  43. }
  44. }

示例效果图

可以使用全局或局部@Builder通过尾随闭包的形式对@ComponentV2装饰的自定义组件中的@BuilderParam装饰的方法进行初始化。

示例2:

收起
自动换行
深色代码主题
复制
  1. @ComponentV2
  2. struct ChildPage {
  3. @Require @Param message: string = '';
  4. @Builder
  5. customBuilder() {
  6. }
  7. @BuilderParam customBuilderParam: () => void = this.customBuilder;
  8. build() {
  9. Column() {
  10. Text(this.message)
  11. .fontSize(30)
  12. .fontWeight(FontWeight.Bold)
  13. this.customBuilderParam()
  14. }
  15. }
  16. }
  17. const builderValue: string = 'Hello World';
  18. @Builder
  19. function overBuilder() {
  20. Row() {
  21. Text(`Global Builder: ${builderValue}`)
  22. .fontSize(20)
  23. .fontWeight(FontWeight.Bold)
  24. }
  25. }
  26. @Entry
  27. @ComponentV2
  28. struct ParentPage {
  29. @Local label: string = 'Parent Page';
  30. @Builder
  31. componentBuilder() {
  32. Row() {
  33. Text(`Local Builder: ${this.label}`)
  34. .fontSize(20)
  35. .fontWeight(FontWeight.Bold)
  36. }
  37. }
  38. build() {
  39. Column() {
  40. ChildPage({ message: this.label }) {
  41. Column() { // 使用局部@Builder,通过组件后紧跟一个大括号“{}”形成尾随闭包去初始化自定义组件@BuilderParam装饰的方法
  42. this.componentBuilder();
  43. }
  44. }
  45. Line()
  46. .width('100%')
  47. .height(10)
  48. .backgroundColor('#000000').margin(10)
  49. ChildPage({ message: this.label }) { // 使用全局@Builder,通过组件后紧跟一个大括号“{}”形成尾随闭包去初始化自定义组件@BuilderParam装饰的方法
  50. Column() {
  51. overBuilder();
  52. }
  53. }
  54. }
  55. }
  56. }

示例效果图

使用@BuilderParam隔离多组件对@Builder跳转逻辑的调用

当@Builder封装的系统组件包含跳转逻辑时,所有调用该@Builder的自定义组件将具备该跳转功能。如果需要禁用特定组件的跳转功能,可使用@BuilderParam来隔离跳转逻辑。

说明

当前示例代码中使用了Navigation组件导航,具体实现逻辑可以查询Navigation指南。

收起
自动换行
深色代码主题
复制
  1. import { HelloWorldPageBuilder } from './helloworld';
  2. import { hilog } from '@kit.PerformanceAnalysisKit';
  3. const DOMAIN = 0x0000;
  4. class NavigationParams {
  5. public pathStack: NavPathStack = new NavPathStack();
  6. public boo: boolean = true;
  7. }
  8. @Builder
  9. function navigationAction(params: NavigationParams) {
  10. Column() {
  11. Navigation(params.pathStack) {
  12. Button('router to page', { stateEffect: true, type: ButtonType.Capsule })
  13. .width('80%')
  14. .height(40)
  15. .margin(20)
  16. .onClick(() => {
  17. // 通过修改@BuilderParam参数决定是否跳转。
  18. if (params.boo) {
  19. params.pathStack.pushPath({ name: 'HelloWorldPage' });
  20. } else {
  21. hilog.info(DOMAIN, 'testTag', '%{public}s', '@BuilderParam setting does not jump');
  22. }
  23. })
  24. }
  25. .navDestination(HelloWorldPageBuilder)
  26. .hideTitleBar(true)
  27. .height('100%')
  28. .width('100%')
  29. }
  30. .height('25%')
  31. .width('100%')
  32. }
  33. @Entry
  34. @Component
  35. struct ParentPage {
  36. @State info: NavigationParams = new NavigationParams();
  37. build() {
  38. Column() {
  39. Text('ParentPage')
  40. navigationAction({ pathStack: this.info.pathStack, boo: true })
  41. ChildPageOne()
  42. ChildPage_BuilderParam({ eventBuilder: navigationAction })
  43. }
  44. .height('100%')
  45. .width('100%')
  46. }
  47. }
  48. @Component
  49. struct ChildPageOne {
  50. @State info: NavigationParams = new NavigationParams();
  51. build() {
  52. Column() {
  53. Text('ChildPage')
  54. navigationAction({ pathStack: this.info.pathStack, boo: true })
  55. }
  56. }
  57. }
  58. @Component
  59. struct ChildPage_BuilderParam {
  60. @State info: NavigationParams = new NavigationParams();
  61. @BuilderParam eventBuilder: (param: NavigationParams) => void = navigationAction;
  62. build() {
  63. Column() {
  64. Text('ChildPage_BuilderParam')
  65. // 对传递过来的全局@Builder进行参数修改,可以实现禁用点击跳转的功能。
  66. this.eventBuilder({ pathStack: this.info.pathStack, boo: false })
  67. }
  68. }
  69. }
收起
自动换行
深色代码主题
复制
  1. @Builder
  2. export function HelloWorldPageBuilder() {
  3. HelloWorldPage()
  4. }
  5. @Component
  6. struct HelloWorldPage {
  7. @State message: string = 'Hello World';
  8. @State pathStack: NavPathStack = new NavPathStack();
  9. build() {
  10. // 用于跳转的子页面
  11. NavDestination() {
  12. Column() {
  13. Text(this.message)
  14. .fontSize(20)
  15. .fontWeight(FontWeight.Bold)
  16. }
  17. }
  18. .height('100%')
  19. .width('100%')
  20. }
  21. }

示例效果图

使用全局和局部@Builder初始化@BuilderParam

在自定义组件中,使用@BuilderParam装饰的变量接收父组件通过@Builder传递的内容进行初始化,由于父组件的@Builder可以使用箭头函数改变当前的this指向,因此使用@BuilderParam装饰的变量会展示不同的内容。

收起
自动换行
深色代码主题
复制
  1. @Component
  2. struct ChildPage {
  3. label: string = 'Child Page';
  4. @Builder
  5. customBuilder() {
  6. }
  7. @BuilderParam customBuilderParam: () => void = this.customBuilder;
  8. @BuilderParam customChangeThisBuilderParam: () => void = this.customBuilder;
  9. build() {
  10. Column() {
  11. this.customBuilderParam()
  12. this.customChangeThisBuilderParam()
  13. }
  14. }
  15. }
  16. const builderValue: string = 'Hello World';
  17. @Builder
  18. function overBuilder() {
  19. Row() {
  20. Text(`Global Builder: ${builderValue}`)
  21. .fontSize(20)
  22. .fontWeight(FontWeight.Bold)
  23. }
  24. }
  25. @Entry
  26. @Component
  27. struct ParentPage {
  28. label: string = 'Parent Page';
  29. @Builder
  30. componentBuilder() {
  31. Row() {
  32. Text(`Local Builder: ${this.label}`)
  33. .fontSize(20)
  34. .fontWeight(FontWeight.Bold)
  35. }
  36. }
  37. build() {
  38. Column() {
  39. // 调用this.componentBuilder()时,this指向当前@Entry所装饰的ParentPage组件,所以label变量的值为'Parent Page'。
  40. this.componentBuilder()
  41. ChildPage({
  42. // 把this.componentBuilder传给子组件ChildPage的@BuilderParam customBuilderParam,
  43. // this指向的是子组件ChildPage,所以label变量的值为'Child Page'。
  44. customBuilderParam: this.componentBuilder,
  45. // 把():void=>{this.componentBuilder()}传给子组件ChildPage的@BuilderParam customChangeThisBuilderParam,
  46. // 因为箭头函数的this指向的是宿主对象,所以label变量的值为'Parent Page'。
  47. customChangeThisBuilderParam: (): void => {
  48. this.componentBuilder()
  49. }
  50. })
  51. Line()
  52. .width('100%')
  53. .height(10)
  54. .backgroundColor('#000000').margin(10)
  55. // 调用全局overBuilder()时,this指向当前整个活动页,所以展示的内容为'Hello World'。
  56. overBuilder()
  57. ChildPage({
  58. // 把全局overBuilder传给子组件ChildPage的@BuilderParam customBuilderParam,
  59. // this指向当前整个活动页,所以展示的内容为'Hello World'。
  60. customBuilderParam: overBuilder,
  61. // 把全局overBuilder传给子组件ChildPage的@BuilderParam customChangeThisBuilderParam,
  62. // this指向当前整个活动页,所以展示的内容为'Hello World'。
  63. customChangeThisBuilderParam: overBuilder
  64. })
  65. }
  66. }
  67. }

示例效果图

在@ComponentV2装饰的自定义组件中使用@BuilderParam

使用全局或局部@Builder初始化@ComponentV2装饰的自定义组件中的@BuilderParam属性。

收起
自动换行
深色代码主题
复制
  1. @ComponentV2
  2. struct ChildPage {
  3. @Param label: string = 'Child Page';
  4. @Builder
  5. customBuilder() {
  6. }
  7. @BuilderParam customBuilderParam: () => void = this.customBuilder;
  8. @BuilderParam customChangeThisBuilderParam: () => void = this.customBuilder;
  9. build() {
  10. Column() {
  11. this.customBuilderParam()
  12. this.customChangeThisBuilderParam()
  13. }
  14. }
  15. }
  16. const builderValue: string = 'Hello World';
  17. @Builder
  18. function overBuilder() {
  19. Row() {
  20. Text(`Global Builder: ${builderValue}`)
  21. .fontSize(20)
  22. .fontWeight(FontWeight.Bold)
  23. }
  24. }
  25. @Entry
  26. @ComponentV2
  27. struct ParentPage {
  28. @Local label: string = 'Parent Page';
  29. @Builder
  30. componentBuilder() {
  31. Row() {
  32. Text(`Local Builder: ${this.label}`)
  33. .fontSize(20)
  34. .fontWeight(FontWeight.Bold)
  35. }
  36. }
  37. build() {
  38. Column() {
  39. // 调用this.componentBuilder()时,this指向当前@Entry所装饰的ParentPage组件,所以label变量的值为'Parent Page'。
  40. this.componentBuilder()
  41. ChildPage({
  42. // 把this.componentBuilder传给子组件ChildPage的@BuilderParam customBuilderParam,
  43. // this指向的是子组件ChildPage,所以label变量的值为'Child Page'。
  44. customBuilderParam: this.componentBuilder,
  45. // 把():void=>{this.componentBuilder()}传给子组件ChildPage的@BuilderParam customChangeThisBuilderParam,
  46. // 因为箭头函数的this指向的是宿主对象,所以label变量的值为'Parent Page'。
  47. customChangeThisBuilderParam: (): void => {
  48. this.componentBuilder()
  49. }
  50. })
  51. Line()
  52. .width('100%')
  53. .height(5)
  54. .backgroundColor('#000000').margin(10)
  55. // 调用全局overBuilder()时,this指向当前整个活动页,所以展示的内容为'Hello World'。
  56. overBuilder()
  57. ChildPage({
  58. // 把全局overBuilder传给子组件ChildPage的@BuilderParam customBuilderParam,
  59. // this指向当前整个活动页,所以展示的内容为'Hello World'。
  60. customBuilderParam: overBuilder,
  61. // 把全局overBuilder传给子组件ChildPage的@BuilderParam customChangeThisBuilderParam,
  62. // this指向当前整个活动页,所以展示的内容为'Hello World'。
  63. customChangeThisBuilderParam: overBuilder
  64. })
  65. }
  66. }
  67. }

示例效果图

常见问题

改变内容UI不刷新

调用自定义组件ChildPage时,通过this.componentBuilder传递@Builder参数。this指向自定义组件内部,因此父组件中改变label的值时,ChildPage无法感知这一变化。

【反例】

收起
自动换行
深色代码主题
复制
  1. @Component
  2. struct ChildPage {
  3. @State label: string = 'Child Page';
  4. @Builder
  5. customBuilder() {
  6. }
  7. @BuilderParam customChangeThisBuilderParam: () => void = this.customBuilder;
  8. build() {
  9. Column() {
  10. this.customChangeThisBuilderParam()
  11. }
  12. }
  13. }
  14. @Entry
  15. @Component
  16. struct ParentPage {
  17. @State label: string = 'Parent Page';
  18. @Builder
  19. componentBuilder() {
  20. Row() {
  21. Text(`Builder :${this.label}`)
  22. .fontSize(20)
  23. .fontWeight(FontWeight.Bold)
  24. }
  25. }
  26. build() {
  27. Column() {
  28. ChildPage({
  29. // 当前写法this指向ChildPage组件内
  30. customChangeThisBuilderParam: this.componentBuilder
  31. })
  32. // 请将$r('app.string.builderOpp_text1')替换为实际资源文件,在本示例中该资源文件的value值为"点击改变label内容"
  33. Button($r('app.string.builderOpp_text1'))
  34. .onClick(() => {
  35. this.label = 'Hello World';
  36. })
  37. }
  38. }
  39. }

使用箭头函数将@Builder传递到自定义组件ChildPage中,this指向会停留在父组件ParentPage里。在父组件中改变label的值时,ChildPage会感知到并重新渲染UI。

【正例】

收起
自动换行
深色代码主题
复制
  1. @Component
  2. struct ChildPage {
  3. @State label: string = 'Child Page';
  4. @Builder
  5. customBuilder() {
  6. }
  7. @BuilderParam customChangeThisBuilderParam: () => void = this.customBuilder;
  8. build() {
  9. Column() {
  10. this.customChangeThisBuilderParam()
  11. }
  12. }
  13. }
  14. @Entry
  15. @Component
  16. struct ParentPage {
  17. @State label: string = 'Parent Page';
  18. @Builder
  19. componentBuilder() {
  20. Row() {
  21. Text(`Builder :${this.label}`)
  22. .fontSize(20)
  23. .fontWeight(FontWeight.Bold)
  24. }
  25. }
  26. build() {
  27. Column() {
  28. ChildPage({
  29. customChangeThisBuilderParam: () => {
  30. this.componentBuilder()
  31. }
  32. })
  33. // 请将$r('app.string.builderOpp_text1')替换为实际资源文件,在本示例中该资源文件的value值为"点击改变label内容"
  34. Button($r('app.string.builderOpp_text1'))
  35. .onClick(() => {
  36. this.label = 'Hello World';
  37. })
  38. }
  39. }
  40. }

@Require装饰器和@BuilderParam装饰器联合使用

由于@Require装饰器所装饰的变量需进行初始化,未初始化会导致编译报错。

【反例】

收起
自动换行
深色代码主题
复制
  1. @Builder
  2. function globalBuilder() {
  3. Text('Hello World')
  4. }
  5. @Entry
  6. @Component
  7. struct CustomBuilderDemo {
  8. build() {
  9. Column() {
  10. // 由于未对@Require装饰的变量ChildBuilder进行赋值,会出现编译和编辑报错。
  11. ChildPage()
  12. }
  13. }
  14. }
  15. @Component
  16. struct ChildPage {
  17. @Require @BuilderParam ChildBuilder: () => void = globalBuilder;
  18. build() {
  19. Column() {
  20. this.ChildBuilder()
  21. }
  22. }
  23. }

@Require装饰的变量必须从外部初始化。

【正例】

收起
自动换行
深色代码主题
复制
  1. @Builder
  2. function globalBuilder() {
  3. Text('Hello World')
  4. }
  5. @Entry
  6. @Component
  7. struct CustomBuilderDemo {
  8. build() {
  9. Column() {
  10. // childBuilder被@Require装饰,必须从外部初始化
  11. ChildPage({ childBuilder: globalBuilder })
  12. }
  13. }
  14. }
  15. @Component
  16. struct ChildPage {
  17. @Require @BuilderParam childBuilder: () => void = globalBuilder;
  18. build() {
  19. Column() {
  20. this.childBuilder()
  21. }
  22. }
  23. }

@BuilderParam装饰器初始化的值必须为@Builder

使用@State装饰器装饰的变量,在初始化子组件@BuilderParam装饰的childBuilder变量时,编译时会输出报错信息。

【反例】

收起
自动换行
深色代码主题
复制
  1. @Builder
  2. function globalBuilder() {
  3. Text('Hello World')
  4. }
  5. @Entry
  6. @Component
  7. struct CustomBuilderDemo {
  8. @State message: string = '';
  9. build() {
  10. Column() {
  11. // @BuilderParam装饰的变量childBuilder接收@State装饰的变量,会出现编译和编辑报错
  12. ChildPage({ childBuilder: this.message })
  13. }
  14. }
  15. }
  16. @Component
  17. struct ChildPage {
  18. @BuilderParam childBuilder: () => void = globalBuilder;
  19. build() {
  20. Column() {
  21. this.childBuilder()
  22. }
  23. }
  24. }

使用全局@Builder装饰的globalBuilder()方法为子组件@BuilderParam装饰的childBuilder变量初始化,编译无报错,功能正常。

【正例】

收起
自动换行
深色代码主题
复制
  1. @Builder
  2. function globalBuilder() {
  3. Text('Hello World')
  4. }
  5. @Entry
  6. @Component
  7. struct CustomBuilderDemo {
  8. build() {
  9. Column() {
  10. // 正确写法
  11. ChildPage({ childBuilder: globalBuilder })
  12. }
  13. }
  14. }
  15. @Component
  16. struct ChildPage {
  17. @BuilderParam childBuilder: () => void = globalBuilder;
  18. build() {
  19. Column() {
  20. this.childBuilder()
  21. }
  22. }
  23. }