I am trying to return data from axios response from service, but I will always receive from service undefined, but inside service I have data. Can you tell what am I doing wrong?
this is how my service looks like:
import axios from 'axios';
export default {
async fetchById (articleId) {
await axios.post('/api/article', { id: articleId })
.then(function (response) {
console.log('axios', response) // valid response
return response.data
})
.catch(function (e) {
console.error('error', e);
});
}
}
And there is my usage in component:
async created () {
const article = await articleService.fetchById('12345')
console.log('article', article) // there I have undefined
}