Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

281
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda