鸿蒙开发模板
如何在DevEco Studio上用插件集成组件&模板
https://developer.huawei.com/consumer/cn/doc/start/components-integration-deveco-0000002218625313
学习
- 美食菜谱应用模板1124
2025-12-15
鸿蒙Harmony跨模块交互
四种不同的包的区分方式,查看该module中的src/main/module.json5文件里面的type字段
hap 应用部署的最小单元
har 静态共享包
hsp 动态共享包
HarmonyOS提供了两种共享包,HAR(Harmony Archive)静态共享包,和HSP(Harmony Shared Package)动态共享包。
ts
build-profile.json5 里面配置静态共享包 和入口文件
模块加载配置入口文件 oh-package.json5 这个里面的dependencies很重要
ts
{
"name": "products",
"version": "1.0.0",
"description": "Please describe the basic information.",
"main": "",
"author": "",
"license": "",
"dependencies": {
"commonlib": 'file:../commons/commonlib'
}
}
菜单跳转
要在resources/base/profile/下新建router_map.json
然后再module.json5里面配置 "routerMap": "$profile:router_map",
三方库中心仓+网路请求
https://ohpm.openharmony.cn/#/cn/home
ts
// 订阅
import { emitter } from '@kit.BasicServicesKit';
@ohos/axios 简化封装
// 文档地址
# https://ohpm.openharmony.cn/#/cn/detail/@ohos%2Faxios
https://developer.huawei.com/consumer/cn/blog/topic/03167186125079020
项目目录
ts
pages
HomePage.ets
utils
types
viewModels
HomePageVM.ets
// 使用示例
@ComponentV2
struct HomePage {
vm: HomePageVM = HomePageVM.instance;
build() {
Text(this.vm.title)
}
}