1

I have a method that is making 2 API calls simultaneously. How can I take the results of the API calls and manipulate them in another method within the same Vue component.

 buildChart(){
    *method where calls would be manipulated"

}
     async updateChart() {
        this.isLoading = true;
        const apiCall1 = await get().then((result) => {
          console.log(result);
          this.isLoading = false;
        });
        const apiCall2= await get().then((result) => {
          console.log(result);
          this.isLoading = false;
        });
      }

1 Answer 1

1

You can use Promise.all to execute the two requests in parallel, the result will be an array of two items of each async request.

async buildChart(){
  // here result will be an array with two items of the result of each async get method.
  const [firstRequest, secondRequest] = await updateChart()
  this.isLoading = false;
},
updateChart() {
  this.isLoading = true;
  return Promise.all([get(), get()])
}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.