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

104
Views
Axios GET requests return empty promises to html

I have tried to make this work all day long, and I have no idea what is happening.

I have this html table using vue v-for (I reduced the code to make it clearer):

<table id="timeSheet-datatable" class="table table-striped dt-responsive w-100">
<thead>
    <tr>
        <th>Project</th>
    </tr>
</thead>
<tbody>
    <tr v-for="(timeSheet,index) in timeSheetListPageable">
        <td>{{getProjectById(timeSheet.projectId)}}</td>
    </tr>                                                   
</tbody>

and I have this js:

async getProjectByIds(param){

   var result = '';
   await axios
       .get(`/project/${param}`).then(response => {
             result= response.data.name;
         }, response => {
             (err) => console.log(err)
         });
   return await result;
},


getProjectById(param){

   const data = this.getProjectByIds(param);

   console.log(data)
   return data;

},

The problem is that I don't know why the return is not working, the table results are empty spaces, and if I add async and await to getProjectById method the return is [object Promise].

The console.log inside the getProjectById works property, it shows the correct returns from the Axios, but the return to the table doesn't work. I already tried to change a lot of things in this code, any suggestions?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

await result after axios.then() construct will not result in the expected sequential flow.

You need to use either promises or multiple await statements to make the code readable and execute properly.

async getProjectByIds(param){

    var result = '';
    try {
        var response = await axios.get(`/project/${param}`)
        result = response.data.name;
    } catch (err) {
        console.error(err)
    }
    return result;
},


async getProjectById(param){

    const data = await this.getProjectByIds(param);

    console.log(data)
    return data;

},

I am not sure about the actual response.data statement. You may or maynot have to use an await there.

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!