基于DevEco Studio的OpenHarmony应用原子化服务(元服务)入门教程

一、创建项目

二、创建卡片

三、应用服务代码

Index.ets

复制代码
@Entry
@Component
struct Index {
  @State TITLE: string = 'OpenHarmony';
  @State CONTEXT: string = '创新召见未来!';

  build() {
    Row() {
      Column() {
        Text(this.TITLE)
          .fontSize(30)
          .fontColor(0xFEFEFE)
          .fontWeight(600)
        Text(this.CONTEXT)
          .fontSize(30)
          .fontColor(0xFEFEFE)
          .fontWeight(600)
          .margin(20)
      }
      .width('100%')
    }
    .width('100%')
    .height('100%')
    .backgroundColor(0x42218c)

  }
}

四、卡片代码

WidgetNewCard.ets

复制代码
@Entry
@Component
struct WidgetNewCard {
  /*
   * The title.
   */
  readonly TITLE: string = 'OpenHarmony';
  readonly CONTEXT: string = '技术构建万物智联';
  /*
   * The action type.
   */
  readonly ACTION_TYPE: string = 'router';

  /*
   * The ability name.
   */
  readonly ABILITY_NAME: string = 'EntryAbility';

  /*
   * The message.
   */
  readonly MESSAGE: string = 'add detail';

  /*
   * The with percentage setting.
   */
  readonly FULL_WIDTH_PERCENT: string = '100%';

  /*
   * The height percentage setting.
   */
  readonly FULL_HEIGHT_PERCENT: string = '100%';

  build() {
    Row() {
      Column() {
        Text(this.TITLE)
          .fontSize(14)
          .fontColor(0xFEFEFE)
          .fontWeight(600)
        Text(this.CONTEXT)
          .fontSize(14)
          .fontColor(0xFEFEFE)
          .fontWeight(600)
      }
      .width(this.FULL_WIDTH_PERCENT)
    }
    .backgroundColor(0x42218c)
    .height(this.FULL_HEIGHT_PERCENT)
    .onClick(() => {
      postCardAction(this, {
        "action": this.ACTION_TYPE,
        "abilityName": this.ABILITY_NAME,
        "params": {
          "message": this.MESSAGE
        }
      });
    })
  }
}

五、运行案例

六、案例卡片效果

注释说明:

现最新版的DevEco Studio中OpenHarmony项目在本目录下调整。将runtimeOS:""中间内容调为OpenHarmony即可。这种方式,不用开发板,通过预览器就可以查看项目样式效果。

完整项目代码地址:

HarmonyOSAPP开发相关组件: 深圳市蛟龙腾飞网络科技有限公司 - Gitee.com

相关推荐
小飞侠在吗22 分钟前
vue ref
前端·javascript·vue.js
悟能不能悟23 分钟前
在 Vue Router 4 中,如何设置base参数
前端·javascript·vue.js
Lovely_Ruby1 小时前
前端er Go-Frame 的学习笔记:实现 to-do 功能(三),用 docker 封装成镜像,并且同时启动前后端数据库服务
前端·后端
kong@react1 小时前
react+ts项目,富文本开发(wangEditor)
前端·react.js·前端框架
重铸码农荣光1 小时前
AI First + Mobile First:用大模型重构下一代应用开发范式
前端·架构·llm
Lovely_Ruby1 小时前
前端er Go-Frame 的学习笔记:实现 to-do 功能(二),前端项目的开发,对接后端
前端
willingtolove1 小时前
使用chrome修改请求参数重新发送请求
前端·chrome
-曾牛1 小时前
CSRF跨站请求伪造:原理、利用与防御全解析
前端·网络·web安全·网络安全·渗透测试·csrf·原理解析
卓码软件测评2 小时前
第三方软件检测机构:【利用测试工具Postman测试沙箱:在Tests标签中编写健壮的质量检查逻辑测试脚本】
javascript·node.js·postman
魂祈梦2 小时前
前端下载多个文件/浏览器批量下载文件
前端·浏览器