How to deal with the situation when both interfaces return and then operate again? what are the solutions?

fetch("http://10.3.134.173/jsonp-test/data/dish_getbypage.php?start=1",
    ).then((response)=>
        response.json()
    ).then((res)=>{
        console.log(res[0].name);
    });
fetch("http://10.3.134.173/jsonp-test/data/dish_getbypage.php?start=2",
    ).then((response)=>
        response.json()
    ).then((res)=>{
        console.log(res[0].name);
    })

initiate a request at the same time, for example, one waits for one second, the other waits for two seconds to return, and then the result is returned, and then the subsequent operations are performed. How to do this, and how to write

in promise.all

Apr.09,2021

let p1 = new Promise((resolve, reject) => {
    // 
    fetch('....').then((res) => {
        resolve(res);
    })
})

let p2 = new Promise((resolve, reject) => {
    // 
    fetch('....').then((res) => {
        resolve(res);
    })
})

Promise.all([p1,p2]).then(data => {
    console.log(data);
})

first of all, mine is based on axios, that is, encapsulated promise

.
        getUser () { 
            return this.$http.get('/api/v1/account/login_user')
        },
        getUserFeedback () {
            return this.$http.get('/api/v1/user_feedbacks')
        }
        
        this.$http.all([this.getUser(),this.getUserFeedback()])
            .then(this.$http.spread(function(acct,perms){
                acctpermsdata
        }))
        

your requirement should be the data of the first interface and then the data of the second interface?


do not use pictures in the code before asking questions

suppose your two promise are Func1 () and Func2 ()

, respectively.
  

Promise.all

Menu