关于vue.js:在asyncawait请求接口中使用thisconfirm需要给thisconfirm添加await

2次阅读

共计 522 个字符,预计需要花费 2 分钟才能阅读完成。

这个问题困扰了我良久,申请完数据,this.$confirm 弹出后,没等到我点确认按钮,就执行的下一步,执行了异步操作,没有实现同步,问题解决:给 this.$confirm 增加 异步期待 await, 并给出显示返回

async checkDeviceID(){
     
  let rst = true  
  await request.post('material_new/checkDeviceID', params).then(async(data)=>{if(data.error){
       rst = await this.$confirm(data.error+'\r 疏忽并保留?', '提醒', {
          confirmButtonText: '确定',
          cancelButtonText: '勾销',
        }).then(() => {return true}).catch(()=>{return false})
      }else{
        this.model.landing_url.url = data.landing_url
        rst = true
      }

  })
          
   return rst
}

总结:因为 this.confirm() 是异步办法,所以异步办法要实现同步时须要减少 await,若 then 办法内还有申请,须要给 then 再减少 async 来实现同步

正文完
 0