When axios calls the same api, and so on many times at the same time, it executes the next step when all of them are returned correctly.

now encapsulates an api called postItemData () {}; when submitting data, the api, is called multiple times in submit () {} through items in an array as follows:

    postItemData(data){ 
        axios.post(data).then()
    },
    submit(array){
        array.forEach(item => {
            this.postItemData(item)
        })
    }

how can I execute the callback function after all requests are returned correctly? Feel that you should use axios.all, how to write the request? Thank you

Oct.25,2021

    postItemData(data){ 
        return axios.post(data)
    },
    submit:async function(array){
        await Promise.all(array.map(item => this.postItemData(item)));
        //
    }

promise.all


  https://zhuanlan.zhihu.com/p/.

Menu