I am facing an issue with the code below that is giving me the error message
Cannot read property 'push' of undefined
:
var vm = new Vue({
el: '#root',
data: {
posts: [],
newPost: {}
},
createPost: function() {
axios.post("api/posts/create", this.newPost).then(function (response) {
this.posts.push(response.data);
})
}
});
Upon checking the network tab in chrome dev tools, I can confirm that the response.data is indeed an object:
{
"id": 131,
"postContent": "<p>test</p>\n",
}
Even though the response data is an object, Can you help me understand why I am receiving this error?