I'm trying to init an empty array in the data and then get a JSON from the server and populate it.
The problem is that the array always have an extra Observer object so when i log it i see this:
empty items array: [ob: Observer]
here is a code excerpt:
data() {
return {
items: []
}
},
created() {
this.$http.get('/api/menus').then(function (response) {
console.log('items before', this.items); //THIS LOGS items before: [__ob__: Observer]
this.items = [].concat(response.body);
this.items.forEach(function (item) {
console.log('item', item);
item.$add('active', false);
item.tests.forEach(function (test) {
test.$add('active', false);
});
});
}).catch(function (err) {
console.error('err', err);
});
},
The problem is that when trying to add a new property to the objects in the array i get an error:
err TypeError: item.$add is not a function
when i debug i see it happens because it considers the observer object as part of the array.
Is it normal? should i just check if $add exists? what about when rendering it in the view, does Vue ignore this object?