在h5 index.html中引入
1.在uniapp中创建webview通信的vue页面 2.h5通信webview中绑定@message uvue中绑定@onmessage 3.h5组件中获取从uniapp传过来的参数(生命周期中获取)
const queryString = window.location.search;
// 使用 URLSearchParams 对象解析查询字符串
const urlParams = new URLSearchParams(queryString);
console.log(urlParams)
4.h5向uniapp传递路由参数 这里注意想要触发postMessage,需要使用uni的路由时间触发
uni.webView.navigateBack()
uni.webView.postMessage({
data: {
}
})
5.h5直接像uniapp中配置的路由跳转
uni.webView.reLaunch({
url:"路径"
})
6.h5 打包放在对应的服务器,用后台返回的url渲染webview的src
好文链接
发表评论