鸿蒙应用笔记

安装就跳过了,一直点点就可以了

配置跳过,就自动下了点东西。

鸿蒙那个下载要12g个内存,大的有点吓人。

里面跟idea没区别

模拟器或者真机运行

真机要鸿蒙4.0,就可以实机调试

直接在手机里面跑,这个牛逼,华为手机厉害

开发语言是arkts,扩展优化语言ts

ts是js扩展,arkts扩展ts

arkts

声明式ui

直接开搞,创建项目

onclick需要参数是事件,其余都感觉挺正常,能看懂

@State 相当于标记变量

有点像注解的这种东西,是装饰器,用来装饰类结构,方法,变量

css相当于定义成方法,自己传参就可以了,该加哪些属性,直接看方法就可以了,记不住,鼠标放上去。

struct就是类似于class

声明式描述ui

内置组件:容器组件,基础组件

容器组件:row,column

基础组件:自带样式的组件,text,button之类的

onclick 事件方法,这个很关键,上事件的。

复制代码
@Entry
@Component
struct Index {
  @State message: string = '123'
  @State b1:number = 0;

  build() {
    Row() {
      Column() {
        Button('点我'+this.b1)
          .backgroundColor('#360d')
          .onClick(()=>{
            this.b1++
          })
      }
      .width('100%')
    }
    .height('100%')
  }
}

不懂直接现看就行,点击show in api 就可以看方法的教学

中间各个组件学习就跳过了,没什么意思,纯纯浪费时间,明明可以看文档就可以懂,到时候用再看就行了,水了那么久视频。

直接快进到进阶点的

渲染控制

if判断,for循环

这?号什么意思,好像是可要可不要的意思,可以省略。

复制代码
ForEach(
  arr: Array, //要遍历的数据数组
  (item: any,index?: number) =>{

  },
  keyGenerator?: (item: any, index?: number): string => {
    
  }
}

图片保存到resource下media文件夹中

遍历显示对象,以及部分格式

下面遍历函数当时听,看的时候有些懵逼,自己实际使用就懂了

应该是这个意思

foreach(自己要遍历的对象,item:形容它的类型)=》回调函数{

}

复制代码
class Item {
  name: string
  image: ResourceStr
  price: number
  discount: number

  constructor(name: string, image: ResourceStr, price: number, discount: number = 0) {
    this.name = name
    this.image = image
    this.price = price
    this.discount = discount
  }
}
@Entry
@Component
struct _for{
  // 商品数据
  private items: Array<Item> = [
    new Item('华为Mate60', $r('app.media.1'), 6999, 500),
    new Item('MateBookProX', $r('app.media.2'), 13999),
    new Item('WatchGT4', $r('app.media.3'), 1438),
    new Item('FreeBuds Pro3', $r('app.media.4'), 1499),
    new Item('Mate X5', $r('app.media.5'), 12999)
  ]
  build() {
    Column({space:10}){
      Row(){
        Text("商品")
          .fontSize(30)
          .backgroundColor('#360d')
          .fontWeight(FontWeight.Bold)
          .textAlign(TextAlign.Start)
      }
ForEach(this.items,(item:Item)=>{
  Row(){
    Image(item.image).width(100).margin({left:20})
    Column(){
      Text(item.name).fontSize(30)
      Text(item.price+"$").fontColor(Color.Red)
    }.margin({left:20})
  }.width("100%")
})

    }

  }
}

效果图

因为不能滑动,为了滑动,所以为什么我们要用list容器

超出的东西,自动提供滚动的功能

想要改变方向listDirecction就可以改变水平还是垂直

代码,遍历的东西,一定要放在ListItem中,不然报错

复制代码
      List({space:10}){
        ForEach(this.items,(item:Item)=>{
          ListItem(){
            Row(){
              Image(item.image).width(100).margin({left:20})
              Column(){
                Text(item.name).fontSize(30)
                Text(item.price+"$").fontColor(Color.Red)
              }.margin({left:20})
            }.width("90%").margin({top:20}).border({width:2,color:Color.Green})
          }

        })

      }

再次成功

相关推荐
xuhaoyu_cpp_java1 小时前
过滤器与监听器学习
java·经验分享·笔记·学习
LegendNoTitle2 小时前
计算机三级等级考试 网络技术 选择题考点详细梳理
服务器·前端·经验分享·笔记·php
键盘鼓手苏苏4 小时前
Flutter 三方库 p2plib 的鸿蒙化适配指南 - 实现高性能的端到端(P2P)加密通讯、支持分布式节点发现与去中心化数据流传输实战
flutter·harmonyos·鸿蒙·openharmony
加农炮手Jinx4 小时前
Flutter for OpenHarmony:postgrest 直接访问 PostgreSQL 数据库的 RESTful 客户端(Supabase 核心驱动) 深度解析与鸿蒙适配指南
数据库·flutter·华为·postgresql·restful·harmonyos·鸿蒙
加农炮手Jinx4 小时前
Flutter 组件 heart 适配鸿蒙 HarmonyOS 实战:分布式心跳监控,构建全场景保活检测与链路哨兵架构
flutter·harmonyos·鸿蒙·openharmony
钛态4 小时前
Flutter 三方库 http_mock_adapter — 赋能鸿蒙应用开发的高效率网络接口 Mock 与自动化测试注入引擎(适配鸿蒙 HarmonyOS Next ohos)
android·网络协议·flutter·http·华为·中间件·harmonyos
Oll Correct4 小时前
实验八:验证以太网交换机的生成树协议STP
网络·笔记
王码码20354 小时前
Flutter for OpenHarmony:Flutter 三方库 algoliasearch 毫秒级云端搜索体验(云原生搜索引擎)
android·前端·git·flutter·搜索引擎·云原生·harmonyos
王码码20354 小时前
Flutter 三方库 dns_client 的鸿蒙化适配指南 - 告别 DNS 劫持、探索 DNS-over-HTTPS (DoH) 技术、构建安全的鸿蒙网络请求环境
flutter·harmonyos·鸿蒙·openharmony·dns_client