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

191
Views
waiting fetch to get the data

On a vue application, on a component, calling API to get some data... the problem is that getting undefined, before the call ends... Possible needed aync/await but getting error when adding

//component code (login.vue)

import store from "@/store";

const { response, error } = store.postTO(url, [{id: "button1"}, {id: "button2"}, {id: "button3"}]);
if (response) {
  console.log(response);
} else {
  console.warn(error);
}


//store.js
export default {
    user : null,
    postTO
}


function postTO(url, postData) {

    const requestOptions = {
        method: "POST",
        headers: { "Content-Type": "application/x-www-form-urlencoded" },
        body: JSON.stringify(postData)
    };
    
    return fetch(url, requestOptions).then(response => 
         response.json().then(data => ({
            data: data,
            status: response.status
        })
    ).then(res => {
        console.log(res.data);
        return {response : res.data, error : "test"};
    }))
    .catch(error => {
        return {response : "test", error : error};
    });

}

illustrated
enter image description here

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

0

In the component you have to wait for the fetch by putting an await before the store.posTo

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!