I have a vue component with 2 methods, deleteActivitat
calls an axios.get method and then, this calls the other vue method reloadActivitats
:
methods: {
reloadActivitats: function () {
this.$store.dispatch(actionTypes.FETCH_ACTIVITATS)
},
deleteActivitat: (activitat) => {
crud.delete(activitat).then((response) => {
this.reloadActivitats() // calls reloadActivitats method
}).catch((error) => {
console.log(error);
});
}
}
But when I run the application the reloadActivitats
method is not executed and the console shows the next error:
TypeError: _this.reloadActivitats is not a function
Any idea of what I'm doing wrong?
Instead of using an arrow function, you need to change the usage to a
function
This is because arrow functions do not bind the value of
this
.this
has to be bound to the vue instance forthis.functionName()
to work.You can also use
deleteActivitat()
syntax as described here.