uniapp develops H5 and app monitors return events (and processing methods that cannot be monitored)

1. Use the page event onBackPress event to monitor the return key

onBackPress(e) {
	//e.from === 'backbutton' 说明如果点击的是物理返回键或导航栏的返回键就进行以下操作
      if (e.from === 'backbutton') {
        if (遮罩层是否隐藏) {
          //如果没隐藏
          //这里写让遮罩层隐藏的代码
        } else {
          //如果隐藏了
          //这里就写返回上一页
           uni.navigateBack()
        }
        //return true 
        //返回值为true 时,表示不执行默认的返回(默认返回上一页),执行自定义的返回
 		//如果要限制必须写成true
        return true;
      }
    },

2. Dakeng cannot monitor and return

The normal back operation is the same as that of Android , but IOS still has a big pit of side sliding , which will not trigger onBackPress .
After reconfirming that side sliding does not trigger onBackPress.

3.1. Solution 1 to solve the big pit

disable sideslip

{
    "path": "pages/xxx/xxx",
    "style": {
        ...
        "app-plus": {
            "popGesture": "none", // 禁用侧滑
            "bounce": "none" // 禁用上下拖动页面
        }
    }
},

3.2. Solution 2 to solve the big pit

Logical thinking: it is to operate on the upper level page that he wants to return to, which is a stupid method but effective

onShow() {},//监听页面首次进入
//
//监听页面离开的话,下面两个必须同时使用,因为离开页面会有两种情况
onHide() {},//监听离开页面
onUnload() {},//监听页面销毁
/

Guess you like

Origin blog.csdn.net/qq_59747594/article/details/125833093