Promise.all()
deleteAllSelected({dispatch,state}){ let cartList = state.cartList; if(cartList){ let PromiseAll = [] cartList.forEach((item)=>{ let promise = item.isChecked == 1 ? dispatch('cartDeleteShop',{skuId:item.skuId}) : '' PromiseAll.push(promise) }) return Promise.all(PromiseAll) } }
console.log一下看看
如果都成功的话 就成功 如果有一个不成功 那么就错误 不执行
try{ await this.$store.dispatch('deleteAllSelected'); this.getData() }catch(e){ //TODO handle the exception alert(e.message) this.getData() }