uni-app webview加载的h5页面,console.log打印webview传递过去的参数,在HBuilderX控制台显示的log数据都为空

uni-app webview加载的h5页面,console.log打印webview传递过去的参数,在HBuilderX控制台显示的log数据都为空

产品分类

uniapp/App

开发环境 版本号 项目创建方式
Windows win10 HBuilderX

示例代码:

写在前面:重要!h5页面(我用的vue),一定要用alert查看结果,console的日志会显示到hbuilerx的控制台里,结果会一直为空,我的版本是2.9.5。

从h5向uniapp传值

步骤一、uniapp代码:

let wv = plus.webview.create( 'http://www.baidu.com/#/clientEdit?aa=1&bb=2','mendMerchant', {  
top:'66px',  
height:'92%',  
},{data:this.userInfo}) //this.userInfo是我要传的对象,不用data键值对的方式传的话,h5接收后会是多个字段,而非一个对象
let currentWebview = this.$mp.page.$getAppWebview()  
currentWebview.append(wv);

步骤二、

方式一,获取plus.webview.create第四个参数传来的值:
document.addEventListener("plusready",function (){  
alert(JSON.stringify(plus.webview.getWebviewById("mendMerchant").data)) //data与uniapp里定义的键名保持一致,那里也是定义的data:this.userInfo  
},false);
方式二(url获取):
alert(this.$route.query.aa)

更多关于uni-app webview加载的h5页面,console.log打印webview传递过去的参数,在HBuilderX控制台显示的log数据都为空的实战教程也可以访问 https://www.itying.com/category-93-b0.html

回到顶部