阅读(1056) (6)

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

2020-08-13 15:24:17 更新

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)
    }
});