js两个异步请求,完了同步处理

参考网页:https://segmentfault.com/a/1190000020349903

    //定义两个http请求方法
    const getList1 = ()=>{
        return new Promise((res,rej) =>{
            //省去get方法获取过程
            .then((json) => resolve(json))
        })
    }
    
    const getList2 = ()=>{
        return new Promise((res,rej) =>{
            //省去get方法获取过程
            .then((json) => resolve(json))
        })
    }
    
    Promise.all([getList1(),getList2()]).then(value => {
        //第一个请求的数据
        const x = value[0];
        
        //第二个请求的数据
        const y = value[1];
        
        //合并操作
        for(const i of x){
            for(const k of y){
              //Todo
            }
        }
    })

 

posted @ 2022-05-16 13:58  jqynr  阅读(402)  评论(0)    收藏  举报