美图齐众专注资阳网站设计 资阳网站制作 资阳网站建设
资阳网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

创新互联百度小程序教程: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. });

    文章题目:创新互联百度小程序教程:swan.offPageNotFound
    文章URL:http://www.zsjierui.cn/article/cceihgj.html

    其他资讯