DEV Community

sium_hossain
sium_hossain

Posted on • Edited on

1 1

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 -

SurveyJS custom survey software

Build Your Own Forms without Manual Coding

SurveyJS UI libraries let you build a JSON-based form management system that integrates with any backend, giving you full control over your data with no user limits. Includes support for custom question types, skip logic, an integrated CSS editor, PDF export, real-time analytics, and more.

Learn more

Top comments (1)

Collapse
 
agentprivatbanka profile image
agent_privatbanka

Promise.all([...])

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs