app向h5传参
设置web-view的src为"",拿到参数后修改src
vue项目中用this.$route.query接收值
h5向app传参
在vue项目的index.html中引入uni.webview.1.5.1.js
<script type="text/javascript" src="https://js.cdn.aliyun.dcloud.net.cn/dev/uni-app/uni.webview.1.5.1.js"></script>
vue项目中通过uni.postMessage实现h5与uniapp打包的安卓app的交互
uni.postMessage({
data: {
action: 'h5向app发消息'
}
});
uniapp中,web-view绑定监听事件
<web-view class="webviewStyles"
:src="url"
@message="getMessage"
@onPostMessage="getPostMessage"></web-view>
//处理接收的消息
getMessage(e) {
console.log("@message 接收成功")
if (e.detail) {
console.log('根据h5传值,调用不同的方法,实现h5与app的交互', e.detail)
}
},
// 方法兼容
getPostMessage(e) {
console.log("@onPostMessage 接收成功")
// uni.showModal({
// content: JSON.stringify(e.detail),
// // content: 'haha',
// showCancel: false
// })
if (e.detail) {
console.log('根据h5传值,调用不同的方法,实现h5与app的交互', e.detail)
}
},