0👍
Inside your $.getJSON
success callback this
is no longer your Vue instance. You need to save a reference to your view before calling $.getJSON
:
var vm = this;
$.getJSON(..., function(tasks) {
...
vm.todos.push(...)
Or, look into vue-resource. It supports the Promise API and automatically binds the Vue instance inside callbacks so you can continue to reference this
. And it’s a lot lighter than jQuery.
0👍
in data
you need to define a default value for todos
and newTodoText
like this
data: function () {
return {
list: [],
todos: [],
newTodoText: ''
}
},
Source:stackexchange.com