Bech
Bech
  • 发布:2024-01-27 20:00
  • 更新:2024-03-27 22:33
  • 阅读:130

在tabbar里的webview几个问题

分类:uni-app

tabbar 有四个页面。tabbar-1,tabbar-2,tabbar-3,tabbar-4

其中tabbar-2如下:
<template>
<web-view src="http://www.abc.com/huodong/uni_land" @message="handleMessage"></web-view>
</template>
用了一个webview加载了一个活动的第三方页面。

  1. 现在手机的返回按钮,总是无法对webview的页面进行回退,直接提示退出应用了。

  2. 自己在webview上加了返回按钮
    wv.setStyle({
    titleNView:{
    'titletext':'活动列表',
    autoBackButton: true
    }
    })
    但是这个webview 的WebviewTitleNViewStyles返回按钮也无法进行返回。这就很奇怪了!

  3. 然后想自定义事件吧,又发现一个诡异的事。默认事件没问题,可是切换tabbar,再返回来绑定的事件全部失效了。即使在onshow里重新注册了也不行。不知道官方是否知道啥原因,求解。

总结下:如果不在tabbar里,webview的默认后退都没问题。

2024-01-27 20:00 负责人:无 分享
已邀请:
Bech

Bech (作者)

折腾了4个小时,1和2已经解决:
留个解决方案让以后人能少走弯路:

onBackPress(e) {    
        if (e.from === 'backbutton') {  
            var currentWeb = this.$scope.$getAppWebview().children()[0]  
            var currentURL = currentWeb.getURL()  

               //这里是我一个逻辑不用看      
            if(currentURL == this.targetURL){                 
                this.loadData()  
            }  

                 //主要是这段  
            currentWeb.canBack(function(e){               
                console.log(e.canBack)  
                if(e.canBack){  
                    currentWeb.back()                     
                }else{  
                    uni.navigateBack()  
                }                 
            })  
            return true  
        }  
    },
q***@qq.com

q***@qq.com

TypeError: Cannot read property 'canBack' of undefined

webview宿主为uniapp,用的nvue

648445400

648445400

安卓可以 ios不行,左滑返回不了 onBackPress没触发

要回复问题请先登录注册