我试图在创建/更新条目之前进行一些验证,如下所示:async save(){ return new Promise((resolve, reject)=>{ if(!this.isCampaignValid){ this.handleError() reject() } else{ this.$store .dispatch('updateCampaign') .then((res)=>{ resolve() this.showNotification(res.message, 'success') }) .catch(error=>{ this.showNotification(error.message, 'error') reject() }) } }) },的isCampaignValid是其计算有效性的计算值。如果广告系列无效,那么我在控制台中收到如下错误:未捕获(承诺)未定义该this.handleError()功能也起作用。如何处理这种承诺错误情况?
2 回答
30秒到达战场
TA贡献1828条经验 获得超6个赞
以防万一handleError()抛出,请尝试:
if (!this.isCampaignValid) {
try {
this.handleError()
} catch (e) {
console.error(e);
}
reject()
}
添加回答
举报
0/150
提交
取消
