Reputation: 387
I'm trying to get into vue.js a little bit and having some issues with pushing an item to an array. The code below is based of a scrimba tutorial and at first I had elaborated on it a little, but then I got the error: "Uncaught typeError: Cannot read property 'push' of undefined".
So I simplified it until I was back at the basics from the tutorial. The error remains though..
let app = new Vue({
el: '#toDoApp',
data: {
todos: [
{ text: 'Learn JavaScript' },
{ text: 'Learn Vue' },
{ text: 'Build something awesome' }
]
}
});
toDoApp.todos.push({ text: 'New item' });
After the push statement, the list should be 4 items, rather than the 3 I see.
I've read some things online saying that it is probably because the variable I'm trying to assign it to isn't an array, but as far as I can tell it is. As well as the fact that I can literally find no difference between this and the tutorial code.
Upvotes: 0
Views: 475
Reputation: 1076
this.todos.push({ text: 'New item' });
OR
app.todos.push({ text: 'New item' });
Upvotes: 1