HarmonyOS view与view之间传递参数,调用方法有哪些方法

HarmonyOS
2024-12-26 13:35:58
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
shlp

组件1

@Component
export default struct TitleComponent {
  message: string = '页面列表'
  build() {
    Row() {
      Text(this.message)
        .fontSize(20)
        .fontWeight(FontWeight.Bolder)
        .height(80)
        .textAlign(TextAlign.Start)
      Image('')
        .width(30)
        .aspectRatio(1)
        .backgroundColor(Color.Red)
        .onClick(() => {
          console.log('设置点击事件')
        })
    }
    .border({ width: { bottom: 1 }, color: Color.Grey })
    .width('90%')
    .justifyContent(FlexAlign.SpaceBetween)
  }
}

组件2

@Component
struct Index {
  @State msg: string = '页面列表'

  build() {
    Column() {
      TitleComponent({ message: this.msg})
    }
    .height('100%')
    .width('100%')
  }
}

在组件2中使用组件1,组件1中的message 值来自于组件2,如果不传则是默认值

分享
微博
QQ
微信
回复
2024-12-26 16:57:49
相关问题
HarmonyOS 对象作为参数传递方法丢失
1498浏览 • 1回复 待解决
HarmonyOS view动态添加
1154浏览 • 1回复 待解决
语音识别的方法哪些
1678浏览 • 1回复 待解决
Flutter 热重载方法哪些
1286浏览 • 1回复 待解决
文本转语音的方法哪些?
1415浏览 • 1回复 待解决
Greenplum哪些通用的处理方法
4482浏览 • 1回复 待解决
HarmonyOS 单纯的渐变View
1127浏览 • 3回复 待解决