uni-app+typescript封装接口异常情况Toast处理

1.定义一个SystemSevice类,封装一个errorHanlder方法,处理error

interface ICustomError {

  message?:string

  title?:string

  alertType?:string

}

errorHanlder(e:Error | ICustomError){

  //断言,我知道传进来的是 ICustomError类型的错误

  const error=e as ICustomError;

  switch(error.alertType){

    case 'toast':

      uni.showToast({

    

    })

    break;

  }

}

posted @ 2021-03-10 15:41  囚龙棒主  阅读(406)  评论(0)    收藏  举报