自定义组件
@component
struct MyComponent {
  private title:string
  build(){
    Text(this.title)
  }
} 

引用组件

@Entry
@Component
struct ItemPage {  
build() {
    myComonent({ title: '列表' })
  }
}

自定义构建函数,可以定义在全局或组件内

// 全局公共样式函数
@Styles function fillScreen(){
  .width('100%')
  .height('100%')
  .backgroundColor('#EFEFEF')
  .padding(20)
}
// 继承模式只能在全局
@Extend(Text) function priceText(){
  .fontColor('#F36')
  .fontSize(18)
}
Logo

讨论HarmonyOS开发技术,专注于API与组件、DevEco Studio、测试、元服务和应用上架分发等。

更多推荐