当前位置:

async,await和try,catch

访客 2024-04-25 912 0

async,await只能处理正常的promise,返回已经兑现的promise,不能处理已拒绝的promise

    async created(){//调用后端fetch接口查询数据let data =  await fetch({url:'goods-type/list/all',method:'get',})}

为了处理已拒绝的promise,加try,catch

  async created() {try {//调用后端接口查询数据let data = await fetch({url: "goods-type/list/all",method: "get",});} catch (e) {console.log(e);}},

发表评论

  • 评论列表
还没有人评论,快来抢沙发吧~