typescript开发vue项目二次封装的axios用return Promise.reject(error) 返回异常,提示[Vue warn]: Error in v-on handler (Promise/async)


 

 

 

二次封装axios时刻意服务端模拟了延迟返回数据的场景,用return Promise.reject(error) 返回异常,报如下错误,

[Vue warn]: Error in v-on handler (Promise/async): "Error: timeout of 5000ms exceeded"

 

export default class Page1 extends Vue {
  private async getList() {
    const {data,pagination} = await getArticles(this.listQuery)
    console.log('data: ',data)
    console.log('pagination: ',pagination)
  }
}

 

解决办法:用 try{} catch(e){} 包裹处理方法

export default class Page1 extends Vue {
  private async getList() {
    try {
      const {data,pagination} = await getArticles(this.listQuery)
      console.log('data: ',data)
      console.log('pagination: ',pagination)
    } catch (e) {
      console.log(e.message)
    }
  }
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM