在循环中进行异步操作时,如何在所有的异步操作都执行完了后再执行

const bspUpdate = {
    systemVersion: '/40001/0/27003',
    boardName: '/40001/0/27004',
    bspVersion: '/40001/0/27007'
}

getDeviceBspInfo(){
                let i=0
                let bsplength = Object.keys(bspUpdate).length;
                for(let key in bspUpdate){
                    getDeviceStatus(this.selectedAgentId, bspUpdate[key]).then((data) => {
                        handleResponse(data, (res) => {
                            if(res.status === "CONTENT"){
                                this[key] = res.content.value;
                                i++;
                                console.log(bsplength)
                                if(i == bsplength){//判断所有的异步操作都执行完成
                                    this.getRepoBSP();
                                }
                            }else{
                                swal("",res.errmsg, "error")
                            }
                            
                        })
                    })
                }
            },

猜你喜欢

转载自blog.csdn.net/margin_0px/article/details/85263233
今日推荐