uniapp app-plus evalJs的使用教程

uniapp app-plus evalJs的使用教程

首先在webview原生页面onLoad/onShow通过$scope获取当前的webview页面,然后执行evalJs()来调用webview h5中的函数,比如下面这个例子就是调用h5中的 getVueMessage 自定义函数

注意:需要等h5页面加载一段事件再去调用函数,否则会报错

onShow(){
that.url = url;
uni.showLoading({
	title: "加载中..",
})
setTimeout(function() {
	uni.hideLoading();
	var currentWebview = that.$scope.$getAppWebview();
	let wv = currentWebview.children()[0];
	wv.evalJS("getVueMessage('" + 参数 + "')");
}, 1000);
}

然后在h5页面接收原生页面传递过来的参数:

function getVueMessage(参数) {
	console.log("option:",参数);
	...执行后面的逻辑
}

你可能感兴趣的:(javascript,webview,javascript,前端)