uniapp打包的安卓app中webview和vue的H5网页之间互相传参

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)
				}
			},

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值