【HarmonyOS 鸿蒙 黑马程序员 学习笔记 99.1】

传递UI

在这里插入图片描述
语法

@BuilderParam 名称1: () => void = this.名称2 //  名称1 和 名称2 进行绑定

@BuilderParam ()里面理解成传参 传参是否有组件
@Builder 默认(无传入组件) 构建在括号后 名称2
build 传入组件 构建在括号前 名称1
模块代码新增

@Component struct c_ui{
  @State img : ResourceStr = ''
  @State str1 : string = '默认内容1'
  @State str2 : string = '默认内容2'

  //  @BuilderParam ()里面理解成传参  传参是否有组件
  //  @Builder 默认(无传入组件) 构建在括号后
  //  build 传入组件  构建在括号前
  @BuilderParam ctbd : () => void = this.dfbd //  把df 绑定到 ct
  @Builder dfbd(){  //  不传组件执行
    Column(){
      Image(this.img).width('12%')
      Text(this.str1)
      Text(this.str2)
    }
  }

  build() { //  传组件执行
    this.ctbd()
  }
}

页面代码新增

//  顶 众筹
      Column(){
        Row(){
          Text(`小米有品众筹`)
          Blank()
          Text(`了解更多众筹 >`)
        }.width(`100%`)
        Row(){
          com.c_ui(){
            Column(){
              Row(){
                Column(){
                  Text(`腰带`)
                  Text(`¥499`)
                }.margin({right: '5%' })
                Blank()
                Image($r('app.media.ic_public_car')).width('15%')
              }
              Text(){
                Span('1107').fontColor('#f00');
                Span(`人支持`);
                Span(`  完成 `);
                Span(`100%`).fontColor('#f00')
              }.fontSize(12)
            }
          }
          //  只要不传入组件 就是默认构建 @Builder
          com.c_ui({img:$r('app.media.ic_public_scan'),str1:'顶级工学',str2:'¥1799'})
          com.c_ui({img:$r('app.media.ic_public_scan'),str1:'龙年飞船',str2:'¥13800'})
        }.width('100%').justifyContent(FlexAlign.SpaceEvenly)
      }

在这里插入图片描述

完整代码

模块代码

@Component struct c_ui{
   
   
  @State img : ResourceStr = ''
  @State str1 : string = '默认内容1'
  @State str2 : string = '默认内容2'

  //  @BuilderParam ()里面理解成传参  传参是否有组件
  //  @Builder 默认(无传入组件) 构建在括号后
  //  build 传入组件  构建在括号前
  @BuilderParam ctbd : () => void = this.dfbd //  把df 绑定到 ct
  @Builder dfbd(){
   
     //  不传组件执行
    Column(){
   
   
      Image(this.img).width('12%')
      Text(this.str1)
      Text(this.str2)
    }
  }

  build() {
   
    //  传组件执行
    this.ctbd()
  }
}

@Component struct com_top_img{
   
   
  @BuilderParam ctbd : () => void
  @State img : ResourceStr = ``
  @State txt : string = ''
  build() {
   
   
    Column(){
   
   
      Image(this.img).width(60)
      Text(this
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值