Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

286
Views
await api call responding after unmounting of component | vue.js

I have an method(doSomething) which will be called on mounted state and also have a CTA to unmount the component. Before the await call finish if user unmount the component with back CTA, the controller is still coming back to unmounted component. How to abort the response coming back to the component.

Vue Component:

doSomething(){
   let data = await someApiCall();
   console.log(data)
}

Store.js(vuex)

someApiCall(){
  axios.get("apicall").then(res => res);
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Instead of abandoning, you could stop the 'unmount CTA' being clickable in the first place - until the doSomething() method has been completed its fetch.

export default {
  data() {
      return {
          isFetching: false,
      }
  },
  methods: {
      async doSomething() {
          this.isFetching = true
          let data = await someApiCall()
      },
      myUnmount() {
          // Do your unmount
      },
  },  
  async mounted(){
      await this.doSomething()
      this.isFetching = false
  }
}

And then bind this to the CTA;

<button @click="myUnmount()" :disabled="isFetching">Unmount</button>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!