[Vuejs]-Can't hit vue method from within axios response

3👍

Replace your

...
.then(function (response) {
  console.log('success');
  this.testFunction();
})
...

by

...
.then(response => {
  console.log(response);
  this.testFunction();
})
...

To avoid context override.

You can also use this code:

...
.then(function (response) {
  console.log(response);
  this.testFunction();
}.bind(this))
...

Or

...
const that = this;
...
.this(function (response) {
  console.log(response);
  that.testFunction();
})
...

Leave a comment