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

535
Visualizações
Wait for an Axios call to finish in Quasar / Vue

I have a function in a Quasar application that needs to call an Web API that I need to wait until I get the results back to call the next function. I've posted my code and I'm sure that I'm missing some await or async or have them in the wrong place.

  Global ex='';   

  testFunction3(arg){
   console.log(arg)
  } , 

  testFunction2(){  
  this.ex = update_Members_data_term("@musc.edu");
  },

  async  testFunction(){  
  await this.testFunction2()

  this.testFunction3(this.ex)
 },

API call:

function update_Members_data_term(term) {
 axios.get(
    'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi', {
        params: {
            db: 'pubmed',
            api_key: '',
            retmode: 'json',
            retmax: 200,
            term: term
        }
    }
).then(async response => {
    return response.data.esearchresult.idlist;      
}).catch(error => {
    console.log(error.response)
})

}

Thanks for the help.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

testFunction2 Doesn't return a Promise so await does nothing. You are actually doing await null;

So the fix will be:

function update_Members_data_term(term) {
    return new Promise((resolve,reject) => {
        axios.get(
            'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi', {
            params: {
                db: 'pubmed',
                api_key: '',
                retmode: 'json',
                retmax: 200,
                term: term
            }
        }
        ).then(async response => {
            resolve(response.data.esearchresult.idlist);
        }).catch(error => {
            reject(error.response)
        })
    });
}

async testFunction2(){  
this.ex = await update_Members_data_term("email_here");
},
  • Note that you might just await axios.get instead of returning a Promise, but I'm not sure what the syntax is.
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