在async/await请求接口中使用this.$confirm,需要给this.$confirm添加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
}
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论