鸿蒙开发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%')
  }
}
相关推荐
加农炮手Jinx几秒前
Flutter for OpenHarmony 实战:flutter_native_splash_ohos 打造丝滑冷启动体验
flutter·华为·harmonyos
bylander2 分钟前
【AI学习】华为AgenticRAN架构调研
人工智能·学习·华为·无线通信·智能体
麟听科技2 分钟前
HarmonyOS 6.0+ 跨端元宇宙社交空间开发实战:3D虚拟形象与分布式交互落地
人工智能·分布式·学习·3d·华为·harmonyos
千逐681 小时前
《鸿蒙备忘录:基于 Flutter for OpenHarmony 的极简本地笔记应用全实现》
笔记·flutter·harmonyos
果粒蹬i1 小时前
【HarmonyOS】鸿蒙Flutter智能家居应用开发实战指南
flutter·智能家居·harmonyos
盐焗西兰花10 小时前
鸿蒙学习实战之路-Reader Kit修改翻页方式字体大小及行间距最佳实践
学习·华为·harmonyos
lbb 小魔仙14 小时前
【HarmonyOS实战】React Native 表单实战:在 OpenHarmony 上构建高性能表单
react native·华为·harmonyos
一只大侠的侠16 小时前
React Native开源鸿蒙跨平台训练营 Day16自定义 useForm 高性能验证
flutter·开源·harmonyos
早點睡39017 小时前
高级进阶 React Native 鸿蒙跨平台开发:@react-native-community-slider 滑块组件
react native·react.js·harmonyos
一只大侠的侠18 小时前
Flutter开源鸿蒙跨平台训练营 Day11从零开发商品详情页面
flutter·开源·harmonyos