webview组件调用html页面并实现互相传值的功能
1.rn页面
html ——> rn
html页面传参
if(window.ReactNativeWebView){ window.ReactNativeWebView.postMessage('值'); }接收html的数据使用接收
onMessage={(event) => this.onMessage(event)} 2.html页面![](/i/l/?n=24&i=blog/2889277/202402/2889277-20240228103102457-2109660314.png)
rn ——> html
rn页面传值
message必须是字符串形式
this.webview.postMessage(message); html页面接收 document.addEventListener('message', function(e) { let a = JSON.parse(e.data) alert(a) }) 注意:在html页面是打印不出来数据的 标签:传参,调用,message,h5,html,rn,webview,页面 From: https://www.cnblogs.com/Lemon111/p/18039235