美文网首页
细说Promise

细说Promise

作者: 爱忽悠的唐唐在晃悠 | 来源:发表于2018-07-10 14:52 被阅读6次

在项目中遇到个问题

 doSomeThing1().then(res=>{
   this.getUserMsg(this.openId).then(res=>{
    console.log(res)
  })
}).catch(err=>{
  console.log(err)
})

在getUserMsg方法调用时,后台返回了错误信息,经过我的处理,会抛出一个异常Promise.reject(err),但是死活捕捉不到。原来是因为我在then中的方法,没有写return。

 doSomeThing1().then(res=>{
  return this.getUserMsg(this.openId).then(res=>{
    console.log(res)
  })
}).catch(err=>{
  console.log(err)
})

相关文章

网友评论

      本文标题:细说Promise

      本文链接:https://www.haomeiwen.com/subject/kmgfpftx.html