I'm having an issue with passing parameters to closures within my view components. If I do the below I get an error telling me this.updateSelection() is not a valid function.
methods: {
getSelectedItems() {
axios.get('api/model/' + this.model.id)
.then(function(response) => {
this.updateSelection(response.data.selectedItems);
})
.catch(error => {
console.log(error);
});
},
updateSelection(selectedItems) {
this.selectedItems = selectedItems;
},
}
I can make it work using the ECMA 6 syntax:
.then(response => {
this.updateSelection(response.data.selectedItems);
})
But I can't work out how I would make the function available to the closure without the ECMA 6 syntax. Something like:
.then(function(response) => {
parent.updateSelection(response.data.selectedItems);
})
Can anyone shed any light on this for me?
Thanks.