HarmonyOS 鸿蒙Next:web嵌入H5,打开H5页面后如何从H5跳转回原生
HarmonyOS 鸿蒙Next:web嵌入H5,打开H5页面后如何从H5跳转回原生
关于HarmonyOS 鸿蒙Next:web嵌入H5,打开H5页面后如何从H5跳转回原生的问题,您也可以访问:https://www.itying.com/category-93-b0.html 联系官网客服。
1. 首先创建要注入到web端的对象
export class ParamClass {
constructor() {
}
// 提供H5调用函数
callArkTS(params: ESObject) {
// emitter线程通信参数
let eventData: emitter.EventData = {
data: params
};
// 发送事件
emitter.emit({eventId: 11}, eventData)
}
}
<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>
2. 把paramClass注入到Web端
@State paramClass: ParamClass = new ParamClass()
Web({src: ‘’, controller: this.webController})
.zoomAccess(false)
.height(‘100%’)
.width(‘100%’)
// 将对象注入到web端
.javaScriptProxy({
object: this.paramClass,
name: “paramClass”,
methodList: [“callArkTS”],
controller: this.webController
})
<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>
3. H5这样写函数
<script>
function callArkTS(id, name) {
let obj = {
‘id’: id,
‘name’: name
}
paramClass.callArkTS(obj);
}
</script>
<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>
4. 在Web组件页面里加上事件监听
aboutToAppear(): void {
// 监听H5点击返回Id
emitter.on({eventId: 11}, (result) => {
// 在这里添加要跳转逻辑, 比如:this.nimblePathStack.pop()
});
aboutToDisappear(): void {
emitter.off(11);
}
<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>
找HarmonyOS工作还需要会Flutter的哦,有需要Flutter教程的可以学学大地老师的教程,很不错,B站免费学的哦:https://www.bilibili.com/video/BV1S4411E7LY/?p=17