hongmeng开发

Image图片组件

Text组件

如在两个限定目录里面定义完后,也要在 base牡蛎下去定义一下,不然会报错

TextInput

Button

Slider

案例
ts 复制代码
@State imageWidth:number=30
  //构建 → 界面
  build() {

    Column(){
      Image($r('app.media.startIcon'))
        .width(this.imageWidth)

      TextInput({placeholder:this.imageWidth.toFixed(0)})
        .width(240)
        .height(40)
        .onChange(value=>{
          this.imageWidth=parseInt(value)
        })

      Row(){
        Button('增加')
          .onClick(()=>{
            this.imageWidth+=10
          })

        Button('缩小')
          .onClick(()=>{
            this.imageWidth-=10
          })
      }

      Slider({
        min:0,
        max:100,
        step:10,
        value:this.imageWidth,
        style:SliderStyle.InSet,//在内还是在外
        direction:Axis.Horizontal,//进度条水平还是 垂直
        reverse:false//是否反向滑动
      }).showTips(true)//是否显示百分比
        .onChange(value=>{
          this.imageWidth=value
        })

    }.width('100%').height('100%').padding(20).backgroundColor(Color.Pink)
    .padding(20)

Column和Row

justifyContent

Divider分割线

渲染控制

案例
ts 复制代码
class Item{
  name:string
  image:ResourceStr
  price:number

  constructor(name:string,image:ResourceStr,price:number) {
    this.name=name
    this.image=image
    this.price=price
  }

}

@Entry
@Component
struct demo {
  @State message:number=1;
  @State color:string='#CCCC'
  @State count:number=8888
  @State imageWidth:number=30

  private items: Array<Item>=[
    new Item('华为60',$r('app.media.app_icon'),6999),
    new Item('华为60',$r('app.media.app_icon'),6999),
    new Item('华为60',$r('app.media.app_icon'),6999),
    new Item('华为60',$r('app.media.app_icon'),6999),
    new Item('华为60',$r('app.media.app_icon'),6999)

  ]

    //构建 → 界面
    build() {

      Column(){
        Text('商品列表').fontSize(24).fontWeight(FontWeight.Bold).width('100%')


        ForEach(this.items,
          (item:Item)=>{
            Row(){
              Image(item.image).width(60)
              Column(){
                Text(item.name).fontSize(16)
                Text(item.price.toFixed(0)).fontColor(Color.Red).fontSize(13)
              }.alignItems(HorizontalAlign.Start)
            }.width('100%').height(80)
            .justifyContent(FlexAlign.SpaceBetween)
            .padding({left:15,right:15})
            .margin({top:30})
            .backgroundColor(Color.White)
            .borderRadius(10)
        })

      }.width('100%').height('100%').padding(20).backgroundColor(Color.Pink)
      .padding(20)
  }
}

list组件

案例
ts 复制代码
class Item{
  name:string
  image:ResourceStr
  price:number

  constructor(name:string,image:ResourceStr,price:number) {
    this.name=name
    this.image=image
    this.price=price
  }

}

@Entry
@Component
struct demo {
  @State message:number=1;
  @State color:string='#CCCC'
  @State count:number=8888
  @State imageWidth:number=30

  private items: Array<Item>=[
    new Item('华为60',$r('app.media.app_icon'),6999),
    new Item('华为60',$r('app.media.app_icon'),6999),
    new Item('华为60',$r('app.media.app_icon'),6999),
    new Item('华为60',$r('app.media.app_icon'),6999),
    new Item('华为60',$r('app.media.app_icon'),6999),
    new Item('华为60',$r('app.media.app_icon'),6999),
    new Item('华为60',$r('app.media.app_icon'),6999),
    new Item('华为60',$r('app.media.app_icon'),6999)

  ]

    //构建 → 界面
    build() {

      Column(){
        Text('商品列表').fontSize(24).fontWeight(FontWeight.Bold).width('100%')
          .margin({bottom:30})

        List({space:20}){
          ForEach(this.items,
            (item:Item)=>{
              ListItem(){
                Row(){
                  Image(item.image).width(60)
                  Column(){
                    Text(item.name).fontSize(16)
                    Text(item.price.toFixed(0)).fontColor(Color.Red).fontSize(13)
                  }.alignItems(HorizontalAlign.Start)
                }.width('100%').height(100)
                .justifyContent(FlexAlign.SpaceBetween)
                .padding({left:15,right:15})
                .backgroundColor(Color.White)
                .borderRadius(10)

              }
            })
        }.layoutWeight(1)



      }.width('100%').height('100%').padding(20).backgroundColor(Color.Pink)
      .padding(20)
  }
}

自定义组件

ts 复制代码
//全局自定义构建函数
@Builder function ItemCard(item:Item){
  Row(){
    Image(item.image).width(60)
    Column(){
      Text(item.name).fontSize(16)
      Text(item.price.toFixed(0)).fontColor(Color.Red).fontSize(13)
    }.alignItems(HorizontalAlign.Start)
  }.width('100%').height(100)
  .justifyContent(FlexAlign.SpaceBetween)
  .padding({left:15,right:15})
  .backgroundColor(Color.White)
  .borderRadius(10)
}

使用:

ts 复制代码
//全局公共样式函数
@Styles function StylesQuan(){
  .width('100%')
  .height('100%')
  .padding(20)
  .backgroundColor(Color.Pink)
  .padding(20)
}

使用:

注意:只能抽取公共的,例如text,image这种有特有属性的组件就用不了

需要**@Extend()**继承该组件才可以(继承模式只能写在全局里)

状态管理

@state

@prop和Link

@Provide和@Consume

@objectLink和@Observed

嵌套对象

数组元素

页面路由

页面动画 有点薄弱

Stage模型

配置文件

UIAbitity生命周期

组件的生命周期

其中builder函数创建后的是和销毁前的是组件生命周期,可以在任意组件中使用,而页面的生命周期只能在@entry中使用

UIAlility启动模式

网络连接

http数据请求
相关推荐
胡小禾2 分钟前
mongoDB-1
数据库·mongodb
天冬忘忧9 分钟前
MongoDB在Linux系统中的安装与配置指南
数据库·mongodb·datax
职教育人1 小时前
金砖软件测试赛项之Jmeter如何录制脚本!
java·测试工具·jmeter·性能优化·集成测试
CodeHackerBhx2 小时前
如何使用VMware安装Linux操作系统
linux·运维·服务器
小阿轩yx2 小时前
小阿轩yx-通过state模块定义主机状态
linux·云计算·运维开发·state定义主机状态·jinja模板
睡不醒的小泽2 小时前
VSCode环境下连接 MySQL 8.0 数据库 (C++)
数据库·windows·vscode
码农小野3 小时前
基于SpringBoot的自习室预订系统
java·spring boot·后端
lizi888884 小时前
单组件的编写
java
java_heartLake4 小时前
设计模式之代理模式
java·设计模式·代理模式
Pakho love4 小时前
Linux:软件包管理器 yum和编辑器-vim使用
linux·编辑器·vim