<template>
<view class="content">
<web-view :src="url"></web-view>
</view>
</template>
<script>
var wv; //计划创建的webview
export default {
data() {
return {
url: 'https://www.baidu.com/',
canBack: false,
}
},
onLoad() {
},
methods: {},
onBackPress(options) {
//let h = plus.webview.getWebviewById(wv.id)
//let url = h.getURL()
//let url = wv.getURL()
if (this.canBack) {
wv.back()
return true //不返回提示再按一次退出应用
}
return false
},
onReady() {
// #ifdef APP-PLUS
let currentWebview = this.$scope
.$getAppWebview() //此对象相当于html5plus里的plus.webview.currentWebview()。在uni-app里vue页面直接使用plus.webview.currentWebview()无效
let that = this
setTimeout(function() {
wv = currentWebview.children()[0]
wv.addEventListener('progressChanged', function(e) {
wv.canBack(function(e) {
that.canBack = e.canBack
})
})
}, 1000); //如果是页面初始化调用时,需要延时一下
// #endif
}
};
</script>
<style>
</style>
uniapp webview网页返回
于 2022-04-23 00:23:11 首次发布