[Vuejs]-Wait for an Axios call to finish in Quasar / Vue

3👍

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.

Leave a comment