I'm trying to set a data object called types when I receive a response in the ready() method.
Like this:
export default {
data () {
return {
types: null
}
},
ready () {
TypeService.showAll(1)
.then(function(data) {
this.types = data.types
});
}
}
But I receive the following error in the console:
Cannot set property 'types' of undefined(…)
But when I console.log like this:
ready () {
TypeService.showAll(1)
.then(function(data) {
console.log(data);
});
}
It's not empty!?!?
What is going on here? It drives me crazy.
--EDIT--
TypeService.showAll(1)
.then(({ data }) => ({
this.types: data.types
}.bind(this)));
