鸿蒙开发HarmonyOS NEXT (一) 入门

最近总听见大家讨论鸿蒙,前端转型的好方向?先入门学习下

++目前官方版本和文档持续更新中++

一、开发环境

提示:要占用的空间比较多,建议安装在剩余空间多的盘

1、下载:官网最新工具 - 下载中心 - 华为开发者联盟 (huawei.com)下载安装即可

2、安装node和sdk(补充:我下载的是2024/6/21发布的5.0.3版本,应该是默认配好了,无需步骤2)

安装好后,新建第一个程序试试看(跟微信开发者工具一样,会默认创建项目结构)

二、ArkTs入门

可参考官网案例初识ArkTS语言 | 华为开发者联盟 (huawei.com)

就是ts变化而来的,写了个小案例检验了一下,ts语法基本都是可用的

三、ArkUI组件

ArkUI(方舟UI框架)-应用框架 | 华为开发者联盟 (huawei.com)

随用随查,非常方便

写个小案例,【通过输入或者点击按钮改变图片大小】

javascript 复制代码
@Entry //装饰器-入口,可以直接作为页面显示
@Component //装饰器-组件
struct Index { //自定义组件
  @State normalWidth: number = 250; //变量-监控

  build() {// UI描述,内部声明式UI结构
    Row() {
      Column(){
        Image($r('app.media.head'))
          .width(this.normalWidth)
          .interpolation(ImageInterpolation.High)
        Flex({ direction: FlexDirection.Row }) {
          Text('调节大小:')
            .width(100)
            .textAlign(TextAlign.Start)
            .padding(10)
          TextInput({text:String(this.normalWidth)})
            .width(180)
            .type(InputType.Number)
            .onChange((value) => {
              this.normalWidth = parseInt(value)
            })
        }
        .height(70)
        .width('90%')
        .padding(10)
        Flex({ direction: FlexDirection.Row }) {
          Button('变大', { type: ButtonType.Normal, stateEffect: true })
            .borderRadius(4)
            .backgroundColor(0x317aff)
            .width(90)
            .height(40)
            .margin(10)
            .onClick(()=>{
              if(this.normalWidth < 300){
                this.normalWidth += 10
              }
            })
          Button('变小', { type: ButtonType.Normal, stateEffect: true })
            .borderRadius(4)
            .backgroundColor(0xF55A42)
            .width(90)
            .height(40)
            .margin(10)
            .onClick(()=>{
              if(this.normalWidth >= 100){
                this.normalWidth -= 10
              }
            })
        }
        .height(70)
        .width('90%')
        .padding(10)
        Slider({
          min:0,
          max:400,
          step:10,
          value:this.normalWidth,
          style:SliderStyle.OutSet,
          direction:Axis.Horizontal,
          reverse:false,
        }).width('90%')
          .blockColor('#36d')
          .showTips(true)
          .onChange(value=>{
            this.normalWidth = value
          })
      }.width('100%')
    }
    .height('100%')
    .width('100%')
  }
}
相关推荐
程序员潘Sir1 小时前
鸿蒙应用开发从入门到实战(六):ArkTS声明式UI和组件化
harmonyos·鸿蒙
猫林老师2 小时前
HarmonyOS数据持久化:Preferences轻量级存储实战
华为·harmonyos
Devil枫7 小时前
鸿蒙深链落地实战:从安全解析到异常兜底的全链路设计
安全·华为·harmonyos
广州腾科助你拿下华为认证8 小时前
华为考试:HCIE数通考试难度分析
大数据·华为
与天仙漫步星海8 小时前
华为基本命令
华为
低调小一13 小时前
Android传统开发 vs Android Compose vs HarmonyOS ArkUI 对照表
android·华为·harmonyos
程序员江同学16 小时前
ovCompose + AI 开发跨三端的 Now in Kotlin App
android·kotlin·harmonyos
猛码Memmat17 小时前
华为HarmonyOS开发文档
华为·harmonyos
祥睿夫子18 小时前
ArkTS 未被深挖的核心点:静态多态限制、静态成员与单例实战
harmonyos