swan.offAppHide

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

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

方法参数

示例

在开发者工具中打开

在开发者工具中打开

在 WEB IDE 中打开

扫码体验

代码示例

百度智能小程序

请使用百度APP扫码

图片示例

swan.offAppHide - 图2

代码示例

  • JS
  1. App({
  2. onLaunch() {
  3. swan.onAppHide(function(res) {
  4. console.log(res);
  5. swan.showModal({
  6. title: 'res',
  7. content: JSON.stringify(res),
  8. showCancel: false
  9. });
  10. });
  11. // 在App onLaunch后约3秒取消事件监听(仅做功能示例,开发者可根据业务逻辑选择取消监听时机)
  12. setTimeout(() => {
  13. swan.offAppHide();
  14. swan.showModal({
  15. title: '',
  16. content: '此后将不再触发swan.onAppHide回调'
  17. showCancel: false
  18. });
  19. }, 3000)
  20. }
  21. });