tt.offAppShow
基础库 1.46.0 开始支持本方法,低版本需做兼容处理。这是一个同步方法。
取消监听小程序进前台事件。
语法
tt.offAppShow(callback);
参数说明
callback
类型 | 默认值 | 必填 | 说明 |
---|---|---|---|
function | 是 | 小程序进前台事件的回调函数 |
返回值
无
扫码体验
请使用字节宿主APP扫码
代码示例
App({
onLaunch: function () {
function myShow() {
console.log("app onShow");
}
tt.onAppShow(myShow);
setTimeout(function () {
tt.offAppShow(myShow);
}, 10000);
},
});
Bug & Tip
- Tip:如果多次使用tt.onAppShow注册了同一个回调函数,之后使用
tt.offAppShow
取消回调,只会取消最早注册的那一个,代码示例:
App({
onLaunch: function () {
function cb() {
console.log("app onShow");
}
tt.onAppShow(cb);
tt.onAppShow(cb);
tt.onAppShow(cb);
tt.offAppShow(cb);
// app onShow 会打印两次,在小程序进前台时
},
});
点击纠错
评价此篇文档