uniapp的web-view嵌入网页,网页与uniapp通信
uniapp端:
<template> <view> <web-view src="http://192.168.0.112:8090/tt/" @message="handleMessage"></web-view> </view> </template> <script> export default { methods: { handleMessage(evt) { console.log('接收到的消息:' + JSON.stringify(evt.detail.data)); } } } </script>
html网页端:
<script type="text/javascript" src="uni.webview.1.5.3.js"></script> <script> document.addEventListener('UniAppJSBridgeReady', function() { uni.postMessage({ data: { id: 1, name:'nihao', } }); }); </script>
uni.webview.1.5.3.js的下载地址:https://gitee.com/dcloud/uni-app
参考: