let url = 'https://pro.m.jd.com/mall/active/Y9FVe619hMoajzqpxky1CQQJAkk/index.html'
let view = plus.webview.create(url,'webview',{top:'30px',bottom:'0px'})
var currentWebview = this.$mp.page.$getAppWebview() //链接地址有介绍app开发时,我们可以用plus.webview.currentWebview获取当前页面,但uni-app里用法不一样,需要这样取当前显示的webview
//#ifdef APP-PLUS
var currentWebview = this.$mp.page.$getAppWebview(); //注意相关操作写在APP-PLUS条件编译下

//或者麻烦一点的
var pages = getCurrentPages();  
var page = pages[pages.length - 1];   
var currentWebview = page.$getAppWebview(); //页面栈最顶层就是当前webview  
// currentWebview 是最外层对象
// 延时是为了正确获取到 child 也就是打开外链地址的web-view对象,overrideUrlLoading阻止外层对象没有用
setTimeout(()=>{
	currentWebview.append(view)
	const child = currentWebview.children()[0]
	//match 正则,阻止匹配的地址,不传match 则全部阻止
	child.overrideUrlLoading({mode:"reject",match:''},(event)=>{
		console.log(event.url)
		//openapp.jdmobile://virtual?params=%7B%22category%22%3A%22jump%22%2C%22des%22%3A%22m%22%2C%22sourceValue%22%3A%22babel
	})
},500)
//#endif

参考地址:uni-app中如何使用5+的原生界面控件(包括map、video、livepusher、barcode、nview)

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐