复制代码可以啦,
<template>
<view>
<web-view :src="url" @message="getMessage"></web-view>
</view>
</template>
<script>
var wv;
export default {
onReady() {
console.log('当前环境:' + uni.getSystemInfoSync().platform);
if(uni.getSystemInfoSync().platform == 'android')
{
var currentWebview = this.$mp.page.$getAppWebview()
setTimeout(function() {
wv = currentWebview.children()[0]
var url222 = wv.getURL();
wv.overrideUrlLoading({mode:'reject',match:'.*\.apk.*'}, function(e){
uni.showLoading({
title: '下载中...',
mask: false
});
var dtask = plus.downloader.createDownload(e.url, {}, function ( d, status ) {
uni.hideLoading();
uni.showToast({
title: '下载成功...',
mask: false,
duration: 1500
});
if ( status == 200 ) {
plus.runtime.install(plus.io.convertLocalFileSystemURL(d.filename),{},{},function(error){
uni.showToast({
title: '安装失败',
mask: false,
duration: 1500
});
})
} else {
uni.showToast({
title: '下载失败,请检查您的网络',
mask: false,
duration: 1500
});
}
});
dtask.start();
});
}, 1000);
}
},
data(){
return {
url:'',
id:'',
banner: {}
}
},
onLoad(option) {
try {
this.banner = JSON.parse(decodeURIComponent(option.query));
} catch (error) {
this.banner = JSON.parse(option.query);
}
this.url = this.banner;
},
methods:{
getMessage(event) {
console.log('提示内容: '+JSON.stringify(event.detail.data));
uni.showModal({
content: JSON.stringify(event.detail.data),
showCancel: false
});
}
}
}
</script>
<style>
</style>
2 个回复
7***@qq.com
有解决方法了没??? 对了 我加你QQ了
大熊被骗 (作者)
复制代码
可以啦, <template> <view> <web-view :src="url" @message="getMessage"></web-view> </view> </template> <script> var wv;//计划创建的webview export default { onReady() { console.log('当前环境:' + uni.getSystemInfoSync().platform);//如果是安卓才执行 if(uni.getSystemInfoSync().platform == 'android') { var currentWebview = this.$mp.page.$getAppWebview() //获取当前页面的webview对象 setTimeout(function() { wv = currentWebview.children()[0] var url222 = wv.getURL(); //console.log('当前网址222: '+url222); // 拦截所有页面跳转,可使用参数拦截.apk的跳转 wv.overrideUrlLoading({mode:'reject',match:'.*\.apk.*'}, function(e){ uni.showLoading({ title: '下载中...', mask: false }); //console.log('拦截的URL666: '+e.url); var dtask = plus.downloader.createDownload(e.url, {}, function ( d, status ) { uni.hideLoading(); uni.showToast({ title: '下载成功...', mask: false, duration: 1500 }); // 下载完成 if ( status == 200 ) { plus.runtime.install(plus.io.convertLocalFileSystemURL(d.filename),{},{},function(error){ uni.showToast({ title: '安装失败', mask: false, duration: 1500 }); }) } else { uni.showToast({ title: '下载失败,请检查您的网络', mask: false, duration: 1500 }); } }); dtask.start(); }); }, 1000); //如果是页面初始化调用时,需要延时一下 } }, data(){ return { url:'', id:'', banner: {} } }, onLoad(option) { // 目前在某些平台参数会被主动 decode,暂时这样处理。 try { this.banner = JSON.parse(decodeURIComponent(option.query)); } catch (error) { this.banner = JSON.parse(option.query); } this.url = this.banner; }, methods:{ getMessage(event) { console.log('提示内容: '+JSON.stringify(event.detail.data)); uni.showModal({ content: JSON.stringify(event.detail.data), showCancel: false }); } } } </script> <style> </style>