百度智能小程序 取消监听小程序切后台事件

2020-09-04 16:28 更新

swan.offAppHide

基础库 3.60.2 开始支持,低版本需做兼容处理。

解释: 取消监听小程序切后台事件。

方法参数

示例 

在开发者工具中打开


图片示例


代码示例

// app.js
App({
    onLaunch() {
        swan.onAppHide(function(res) {
            console.log(res);
            swan.showModal({
                title: 'res',
                content: JSON.stringify(res),
                showCancel: false
            });
        });
        // 在App onLaunch后约3秒取消事件监听(仅做功能示例,开发者可根据业务逻辑选择取消监听时机)
        setTimeout(() => {
            swan.offAppHide();
            swan.showModal({
                title: '',
                content: '此后将不再触发swan.onAppHide回调',
                showCancel: false
            });
        }, 3000)
    }
});


以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号