[Vuejs]-How to pass axios response to function argument?

0👍

Use getLatestCommentData like a function. Declare it:

function getLatestCommentData(dataList) {
  if (dataList.length === 0) {
    return {}
  } else {
    return {
      body: dataList[0].body,
      created_at: dataList[0].created_at
    }
  }
}

And use it somewhere later:


posts.map(async (post) => ({
  ...post,
  latestComment: getLatestCommentData(await this.$axios.$get(`/posts/${post.id}/comment`))
  })
);

Leave a comment