用try catch改写下列代码 soHeadersSavePC(dataObj) .then(async (res) => { if (res.status !== "S") { this.fullscreenLoading = false; return ui.error(res.msg); } else { this.fullscreenLoading = false; ui.success("保存成功"); let orderInfo: any = await baseService.get( "/saleServer/dtwmsSoHeaders/findById", { headerId: res.data } ); if (orderInfo.status == "S") { emits.emit(EMitt.OnReloadTabPage); //刷新当前标签页 this.$router.replace({ //跳转销售单详情页 name: "salesOrderDetail", query: { headerId: orderInfo.data.headerId, orderCode: orderInfo.data.orderCode, freightFee: orderInfo.data.freightFee, orderStatusName: orderInfo.data.orderStatusName }, }); } } })
时间: 2024-02-10 07:14:36 浏览: 92
可以使用try-catch重写如下:
```
try {
const res = await soHeadersSavePC(dataObj);
if (res.status !== "S") {
this.fullscreenLoading = false;
return ui.error(res.msg);
} else {
this.fullscreenLoading = false;
ui.success("保存成功");
let orderInfo: any = await baseService.get(
"/saleServer/dtwmsSoHeaders/findById",
{ headerId: res.data }
);
if (orderInfo.status == "S") {
emits.emit(EMitt.OnReloadTabPage); //刷新当前标签页
this.$router.replace({
//跳转销售单详情页
name: "salesOrderDetail",
query: {
headerId: orderInfo.data.headerId,
orderCode: orderInfo.data.orderCode,
freightFee: orderInfo.data.freightFee,
orderStatusName: orderInfo.data.orderStatusName,
},
});
}
}
} catch (error) {
console.error(error);
// handle the error here
}
```
在这个版本中,我们使用了async/await来等待异步操作的结果,并使用try-catch来捕获任何潜在的异常。如果一个异常被抛出,它将被捕获并且错误将被记录在控制台上。
阅读全文