场景说明: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
});
}
},
1 个回复
DCloud_UNI_yuhe
hello , 可以看一下文档:https://uniapp.dcloud.net.cn/component/web-view.html#app%E7%AB%AFweb-view%E7%9A%84%E6%89%A9%E5%B1%95