DEV Community

sium_hossain
sium_hossain

Posted on • Edited on

How to send multiple requests parallelly in fetch hook - Nuxt

Let's declare a method to fetch data from multiple endpoint.

methods:{
// rest of your methods 
async fetchData(){
     let [res1, res2, res3] = await Promise.all(
         this.$axios.$get('api/endpoint/1'),
         this.$axios.$get('api/endpoint/2'),
         this.$axios.$get('api/endpoint/3'),
         )
     // check your response and whatever you want with those response
     console.log(res1)
     console.log(res2)
     console.log(res3)
}
Enter fullscreen mode Exit fullscreen mode

Then you can call this method in fetch hook -

async fetch(){
      await this.fetchData()
}
Enter fullscreen mode Exit fullscreen mode

Thank you

😎 Read more -

Top comments (1)

Collapse
 
agentprivatbanka profile image
agent_privatbanka

Promise.all([...])