• uniapp的webview实现左滑返回上一个页面


    uniapp默认左滑是关闭整个webview,而不是关闭当前页 实现思路:拦截webview的url跳转操作,将新url用webview组件重新打开,当左滑的时候,默认关闭的就是当前webview,继而跳转到上一次的页面中

    <template>
    	<view>
    		<web-view :src="weburl" :update-title="false" :webview-styles="webviewStyles">
    		web-view>
    	view>
    template>
     
    <script>
    	export default {
    		data() {
    			return {
    				// 进度条
    				webviewStyles: {
    					progress: {
    						color: '#FF3333'
    					}
    				},
    				weburl: ""
    			};
    		},
    		onLoad(option) {
    			console.log("接收到的url参数是:", option.weburl); //打印出上个页面传递的参数。
    			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("点击了标题栏按钮")
    			uni.$emit("showMenu")
    		},
    		methods: {}
    	}
    script>
     
    <style lang="scss">
     
    style>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
  • 相关阅读:
    Golang-01Golang开发环境配置
    启山智软商城源码新官网震撼上线
    C语言实现调用python绘图
    软考-代码分析
    面试官:说说SSO单点登录的实现原理?
    C#学习记录——基本图形绘制
    C# 自定义控件库之Lable组合控件
    MARL值分解方法总结(1)
    20240311 大模型快讯
    如何在 Spring Boot 中进行数据备份
  • 原文地址:https://blog.csdn.net/withkai44/article/details/132775452