async pdfConfirm(docId) {
// debugger;
let data = { docId: docId, isPost: 1 };
// changeStatus 状态为4调确认接口
if (this.newFileParam.changeStatus == 5) {
// 新文件确认
await newFileConfirm({ modifyNo: this.newFileParam.modifyNo })
.then(res => {
if (res.code == '999999') {
this.dialogVisible = false;
this.reflashGoods();
return;
}
})
.catch(error => {
console.log(error.message);
this.dialogVisible = false;
this.reflashGoods();
return;
});
}
// 旧文件确认
modifityPdfNote(data)
.then(res => {
// console.log(res.data);
console.log('1111');
this.dialogVisible = false;
this.reflashGoods();
})
.catch(() => {
this.dialogVisible = false;
this.reflashGoods();
});
},
为什么return没用
我改成这样是可以的
// 旧文件确认
oldFilesConfirm(data) {
// 旧文件确认
modifityPdfNote(data)
.then(res => {
// console.log(res.data);
console.log('1111');
this.dialogVisible = false;
this.reflashGoods();
})
.catch(() => {
this.dialogVisible = false;
this.reflashGoods();
});
},
// pdf 确认窗口
async pdfConfirm(docId) {
// debugger;
let data = { docId: docId, isPost: 1 };
// changeStatus 状态为4调确认接口
if (this.newFileParam.changeStatus == 5) {
// 新文件确认
newFileConfirm({ modifyNo: this.newFileParam.modifyNo })
.then(res => {
if (res.code == '000000') {
this.oldFilesConfirm(data);
} else {
this.dialogVisible = false;
this.reflashGoods();
}
})
.catch(error => {
console.log(error.message);
this.dialogVisible = false;
this.reflashGoods();
});
} else {
this.oldFilesConfirm(data);
}
},
在异步函数内使用
return
当然没有效果啊……看了一下你的两个
return
的位置,所以直接使用if……else
不就好了吗。更新:
既然你本来调用就是链式的,所以直接把新/旧文件确认拿到外部作为单独的函数就好了,也就不需要使用
async/await
了,因为你其实也不需要去等待。大概改了一下业务逻辑,你自己还可以优化一下: