1.基本使用:
<web-view src="localhost:8080/chooseFile.html" />
2.小程序向H5传递参数:
①在url拼接参数的方法向H5传递参数:
<web-view src="https://tyzf.jsaisino.com/chooseFile.html?id=1" />
②H5获取参数:
const url = new URL(window.location.href);
const id = url.searchParams.get('id');
3.H5向小程序传递参数,使用@message实现:
①小程序相关代码:
<template>
<view class="container">
<web-view src="/chooseFile.html?id=1" @message="receiveMessage" />
</template>
<script>
export default {
methods: {
receiveMessage(e) {
let files = e.detail.data[0].htmlData;
}
}
}
</script>
②H5相关代码
<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
<script type="text/javascript" src="https://unpkg.com/@dcloudio/uni-webview-js@0.0.3/index.js"></script>
uni.postMessage({
data: {
htmlData: 'html向小程序传递参数'
}
});