H5端:
1、找到index.html引入依赖
<script type="text/javascript" src="https://unpkg.com/@dcloudio/uni-webview-js@0.0.3/index.js"></script>
2、在需要通讯处发送消息
uni.postMessage({data:{code:200,msg:"处理完成"}
})
uniapp端:
使用@message="handlerMessage"
<web-view @message="handlerMessage" :fullscreen="false":src="data.type===1?`${BASE_URL}#/tiopc?id=${data.id}&class_id=${class_id}`:data.url"></web-view>
回调的event里有所需信息
function handlerMessage(event) {console.log("接收到信息");let {code,msg} = event.detail.data[0]if(code !== 200){uni.showToast({title:msg,icon:"error"})return}setTimeout(() => {uni.navigateBack()}, 1500)}