Using Axios in VueJS - this undefined Using Axios in VueJS - this undefined vue.js vue.js

Using Axios in VueJS - this undefined


You're creating a new local function scope. Use fat arrow instead.

.catch((error) => {      console.error(error.response);      if ( error.message === "Network Error" ) {          this.alert.show = 1;          this.alert.message = error.message + ': Please try again later';      }  });


You could also assign this to a global variable and access it inside callback :

    let that =this;    ...    .catch((error) => {  console.error(error.response);  if ( error.message === "Network Error" ) {      that.alert.show = 1;      that.alert.message = error.message + ': Please try again later';  }  });