Loading

es6 Promise.all()的使用

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()
            }

 

posted @ 2022-03-10 17:58  mingBolg  阅读(96)  评论(0)    收藏  举报