欢迎光临
我们一直在努力

九八云百度小程序教程:swan.offPageNotFound

  • swan.offPageNotFound
    • 方法参数
      • callback 参数说明
    • 示例
      • 图片示例
      • 代码示例

    swan.offPageNotFound

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

    解释: 取消监听小程序要打开的页面不存在事件。

    方法参数

    Function callback

    callback 参数说明

    小程序要打开的页面不存在事件的回调函数(swan.onPageNotFound 的回调方法引用);当不传参数时,取消该类全部监听事件。

    示例

    在开发者工具中打开

    在开发者工具中打开

    在 WEB IDE 中打开

    扫码体验

    代码示例

    请使用百度APP扫码

    图片示例

    代码示例

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

    赞(0) 打赏
    未经允许不得转载:九八云安全 » 九八云百度小程序教程:swan.offPageNotFound

    评论 抢沙发