En una aplicación vue, en un componente, llamando a la API para obtener algunos datos... el problema es que se vuelve indefinido , antes de que finalice la llamada ... Posiblemente se necesita aync/await pero se obtiene un error al agregar
//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}; }); }En el componente, debe esperar la recuperación colocando un await antes de store.posTo