uniapp默認(rèn)左滑是關(guān)閉整個(gè)webview,而不是關(guān)閉當(dāng)前頁(yè) 實(shí)現(xiàn)思路:攔截webview的url跳轉(zhuǎn)操作,將新url用webview組件重新打開(kāi),當(dāng)左滑的時(shí)候,默認(rèn)關(guān)閉的就是當(dāng)前webview,繼而跳轉(zhuǎn)到上一次的頁(yè)面中
<template>
<view>
<web-view :src="weburl" :update-title="false" :webview-styles="webviewStyles">
</web-view>
</view>
</template>
<script>
export default {
data() {
return {
// 進(jìn)度條
webviewStyles: {
progress: {
color: '#FF3333'
}
},
weburl: ""
};
},
onLoad(option) {
console.log("接收到的url參數(shù)是:", option.weburl); //打印出上個(gè)頁(yè)面?zhèn)鬟f的參數(shù)。
this.weburl = option.weburl
},
onReady() {
var pages = getCurrentPages();
var page = pages[pages.length - 1];
var currentWebview = page.$getAppWebview();
var url = currentWebview.children()[0].getURL();
console.log('=== url ===', url);
var wv = currentWebview.children()[0];
wv.overrideUrlLoading({
mode: 'reject',
match: '.*'
}, function(e) {
console.log('reject url: ' + e.url);
uni.navigateTo({
url: `/pages/webbox/webbox?weburl=${e.url}`
})
});
},
onBackPress(e) {
let pages = getCurrentPages()
let page = pages[pages.length - 1];
let currentPages = page.$getAppWebview()
currentPages.close()
return false
},
onNavigationBarButtonTap() {
console.log("點(diǎn)擊了標(biāo)題欄按鈕")
uni.$emit("showMenu")
},
methods: {}
}
</script>
<style lang="scss">
</style>
文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-736236.html
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-736236.html
到了這里,關(guān)于uniapp的webview實(shí)現(xiàn)左滑返回上一個(gè)頁(yè)面的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!