swan.offAppShow

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

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

方法参数

示例

在开发者工具中打开

在开发者工具中打开

在 WEB IDE 中打开

扫码体验

代码示例

百度智能小程序

请使用百度APP扫码

图片示例

swan.offAppShow - 图2

代码示例

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