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数据请求
相关推荐
桦说编程11 分钟前
从 ForkJoinPool 的 Compensate 看并发框架的线程补偿思想
java·后端·源码阅读
躺平大鹅2 小时前
Java面向对象入门(类与对象,新手秒懂)
java
初次攀爬者3 小时前
RocketMQ在Spring Boot上的基础使用
java·spring boot·rocketmq
花花无缺3 小时前
搞懂@Autowired 与@Resuorce
java·spring boot·后端
倔强的石头_3 小时前
kingbase备份与恢复实战(二)—— sys_dump库级逻辑备份与恢复(Windows详细步骤)
数据库
Derek_Smart4 小时前
从一次 OOM 事故说起:打造生产级的 JVM 健康检查组件
java·jvm·spring boot
NE_STOP5 小时前
MyBatis-mybatis入门与增删改查
java
孟陬8 小时前
国外技术周刊 #1:Paul Graham 重新分享最受欢迎的文章《创作者的品味》、本周被划线最多 YouTube《如何在 19 分钟内学会 AI》、为何我不
java·前端·后端
想用offer打牌8 小时前
一站式了解四种限流算法
java·后端·go
chlk1239 小时前
Linux文件权限完全图解:读懂 ls -l 和 chmod 755 背后的秘密
linux·操作系统