I want to run getComments()
function inside an object value
loadFeeds: function () {
var self = this;
axios.get('http://localhost:9001/posts', {
headers: {
'Authorization': 'Bearer asdasdasdasdasd'
}
}).then(function (response) {
if (response.status == 200){
if(response.data){
response.data.forEach(function (data) {
self.timeline.unshift({
postId : data.id,
postTime: data.createdAt,
postPrivacy: data.postPrivacy,
post: data.post,
posterId: self.newUpdate.posterId,
posterName: self.newUpdate.posterName,
posterThumb: '',
reactions:'',
comments: self.getComments(data.id)
})
});
}
}
}).catch(function (error) {
console.log(error);
});
},
And below is getComments
function
getComments : function (postId) {
var theComments = [];
axios.get('http://localhost:8001/posts/'+postId+'/comments', {
headers: {
'Authorization': 'Bearer asdadasdasdasdadas'
}
}).then(function (response) {
if (response.status == 200){
if(response.data){
response.data.forEach(function (comment) {
console.log(comment)
theComments.push({
commentId: comment.id,
comment: comment.comment,
commenterId: comment.commenterId,
createdAt: comment.createdAt
})
});
return theComments;
}
}
}).catch(function (error) {
console.log(error);
});
}
The getComments
function is executed successfully, the request is executed successfully with data responses, but it fail to return the data to the caller. How can I return the data to the caller?