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

这个问题困扰了我良久, 申请完数据, 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 来实现同步

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理