[Vuejs]-Vue.js Consuming API through Axios giving error : Uncaught (in promise) TypeError: Cannot read property 'protocol' of undefined

-1👍

You’re referencing the wrong object in your Axios callback. Try adding let self = this at the beginning of your submit method and then in your callback, change this.isSubmit by self.isSubmit.

submitLogin: function(){
  let self = this;
  this.isSubmit = true;
  axios.post()
  axios({
     method: 'post',
     url: urlLogin,
     data: {
         email: this.email,
         password: this.password
     }
  }).then(res =>{
     console.log(res.data);
     self.isSubmit = false;
     localStorage.setItem("token", res.data.access_token);
     localStorage.setItem("name", res.data.fullname);
     window.location.replace("./input-mobile.html");
  }, err =>{
     console.log(err);
     self.isSubmit = false;
  });
}

Leave a comment