当前位置: 首页 > ds >正文

uniapp 嵌入鸿蒙原生组件 具体步骤

关于怎么使用uniapp 嵌入鸿蒙原生组件

HBuilder X 版本 4.64

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

app-harmony文件下新建 index.uts button.ets

在这里插入图片描述

button.ets里面复制uniapp 官方提供的 示例代码

https://uniapp.dcloud.net.cn/tutorial/harmony/native-component.html

button.ets

import { NativeEmbedBuilderOptions, defineNativeEmbed } from "@dcloudio/uni-app-runtime"interface ButtonBuilderOptions extends NativeEmbedBuilderOptions {label: string
}interface ButtonClickEventDetail {text: string
}@Component
struct ButtonComponent {@Prop label: stringonButtonClick?: Functionbuild() {Button(this.label).width('100%').height('100%').onClick(() => {if (this.onButtonClick) {const detail = {text: 'test'} as ButtonClickEventDetailthis.onButtonClick({detail})}})}
}@Builder
function ButtonBuilder(options: ButtonBuilderOptions) {ButtonComponent({label: options.label,onButtonClick: options?.on?.get('click')}).width(options.width).height(options.height)
}defineNativeEmbed('button', {builder: ButtonBuilder
})

index.vue

<template><embed class="native-button" tag="button" :options="options" @click="onClick"></embed>
</template><script setup lang="ts">
import "@/uni_modules/native-harmony-button";
import { ref } from 'vue';
const options = ref({ label: 'hello' })
const onClick = (e) => {console.log(e)
}
</script>
<style lang="scss" scoped>.native-button {display: block;width: 200px;height: 50px;margin: 10px auto;
}
</style>

效果图

在这里插入图片描述

完结

效果没出来的可以在评论区提问

http://www.xdnf.cn/news/8379.html

相关文章:

  • 封装WPF中列表控件的剪贴板操作(附源码)
  • 如何通过用户体验设计提升Shopify独立站的信任度
  • 云原生安全核心:云安全责任共担模型(Shared Responsibility Model)详解
  • 解锁C++编辑距离:文本相似度的度量密码
  • 界面组件DevExpress WPF中文教程:Grid - 行和卡片
  • 扫描电镜:打开微观世界的“超维相机“
  • [实战]用户系统-2-完善登录和校验以及VIP
  • Python打卡第34天
  • PETR- Position Embedding Transformation for Multi-View 3D Object Detection
  • leetcode 61. Rotate List和86. Partition List
  • 【心海资源】黄金首饰价格查询单页源码
  • 如何在 Windows 11 或 10 上通过 PowerShell 安装 Docker Desktop
  • Centos7和Centos8版本功能对比
  • 系统性能分析基本概念(2):性能模型
  • ​​Resin-3.1.12-01 安装教程:详细步骤与配置指南(Linux环境)
  • 【运维实战】nginx版本升级
  • 我的世界模组开发——水平方向的方块(3)
  • 5.22本日总结
  • 人形机器人,进入第一阶段概念设计和起泡沫的阶段
  • 组合问题(分割字符串)
  • 【Java持久层框架对比与使用】
  • 【详解自定义类型:联合和枚举】:联合体类型的声明、特点、大小的计算,枚举类型的声明、优点和使用
  • 522UART是什么
  • 4. 寻找两个正序数组的中位数
  • 复盘20250522
  • C++:list容器,deque容器
  • 六大设计原则
  • 如何在 FastAPI 中合理使用 Pydantic 的 Alias
  • UE4 Simulation Stage 制作 平流
  • 开疆智能Profinet转RS485网关连接富士电机配置案例