I am attempting to assign a data object named types
upon receiving a response in the ready()
method.
This is what I have:
export default {
data () {
return {
types: null
}
},
ready () {
TypeService.showAll(1)
.then(function(data) {
this.types = data.types
});
}
}
However, I am encountering the following error in the console:
Cannot set property 'types' of undefined(…)
Interestingly, when I log like this:
ready () {
TypeService.showAll(1)
.then(function(data) {
console.log(data);
});
}
The data is not empty!?!?
https://i.stack.imgur.com/mWG2V.png
I am puzzled by this situation. It's frustrating me.
--EDIT--
TypeService.showAll(1)
.then(({ data }) => ({
this.types: data.types
}.bind(this)));