鸿蒙开发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%')
  }
}
相关推荐
编程乐学4 小时前
鸿蒙非原创--DevEcoStudio开发的奶茶点餐APP
华为·harmonyos·deveco studio·鸿蒙开发·奶茶点餐·鸿蒙大作业
鸣弦artha5 小时前
Flutter框架跨平台鸿蒙开发 —— Text Widget:文本展示的艺术
flutter·华为·harmonyos
lili-felicity6 小时前
React Native for Harmony:Rating 评分组件- 支持全星 / 半星 / 禁用 / 自定义样式
react native·华为·harmonyos
grd46 小时前
RN for OpenHarmony 小工具 App 实战:屏幕尺子实现
笔记·harmonyos
No Silver Bullet6 小时前
HarmonyOS NEXT开发进阶(十九):如何在 DevEco Studio 中查看已安装应用的运行日志
华为·harmonyos
大雷神8 小时前
HarmonyOS智慧农业管理应用开发教程--高高种地
华为·harmonyos
南村群童欺我老无力.9 小时前
Flutter 框架跨平台鸿蒙开发 - 开发双人对战五子棋游戏
flutter·游戏·华为·typescript·harmonyos
夜雨声烦丿9 小时前
Flutter 框架跨平台鸿蒙开发 - 消消乐游戏开发教程
flutter·游戏·华为·harmonyos
数通工程师10 小时前
IPv4和IPv6 地址分配:从划分到工具全解析
网络·网络协议·tcp/ip·华为
夜雨声烦丿10 小时前
Flutter 框架跨平台鸿蒙开发 - 数独求解器开发教程
flutter·游戏·华为·harmonyos