[Vuejs]-Javascript data.map is not a function

2👍

From your question, I’m assuming your res value from await axios.get(url) looks like this:

{
     posts: [],
     error: "",
     text: ""
}

If thats the case, it is an object, not an array. Map is an array builtin function (array.map)

What you want to map is the posts array in the response

data.posts.map(post => ({
            ...post,
            createdAt: new Date(post.createdAt)
          }))

Leave a comment