阅读(238) (6)

百度智能小程序 取消监听小程序错误事件

2020-08-13 15:24:47 更新

swan.offError

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

解释: 取消监听小程序错误事件。

方法参数

示例 

在开发者工具中打开


图片示例


代码示例

// app.js
App({
    onLaunch() {
        swan.onError(function(errMsg) {
            console.log(errMsg);
            swan.showModal({
                title: '',
                content: JSON.stringify(errMsg)
            });
        });
    },
    // 在App onShow后约3秒取消事件监听(仅做功能示例,开发者可根据业务逻辑选择取消监听时机)  
    onShow() {
        setTimeout(function() {
            swan.offError();
            swan.showModal({
                title: '',
                content: '此后点击按钮触发报错,将不会触发swan.onError事件.'
            });
        }, 3000);
    }
});