2***@qq.com
2***@qq.com
  • 发布:2025-04-24 11:14
  • 更新:2025-04-24 11:21
  • 阅读:76

uniapp开发的h5和uniapp开发的app,h5如何向app发送消息

分类:uni-app

场景说明:h5通过点击事件跳转到app中的某个页面,目前设想的方案是h5传值给app的webview, webview拿到值后做进一步处理例如跳转页面等。

在h5端分别使用了如下,发现都不行,h5端报uni.webView undfined,
1.(uni as any).webView.postMessage
2.window.parent.postMessage
3.window.postMessage
4.uni.postMessage

app webview:
<web-view :src="url" @message="getMessage"></web-view>
getMessage(e) {
try {
uni.showToast({
title: '消息接收成功!',
icon: 'success',
duration: 2000
});
// // eslint-disable-next-line no-console
// // console.log('getMessage==', e);
// // #ifdef APP-PLUS
// let messageList = e.detail.data;
// }
// // #endif
} catch (err) {
uni.showToast({
title: '消息接收失败!',
icon: 'none',
duration: 2000
});
}
},

2025-04-24 11:14 负责人:无 分享
已邀请:

要回复问题请先登录注册