0

I am trying to redirect to home page after login using this.$router.push({name:"Home"}). But its not redirecting to my home page and in console I am getting an error. The error is

     **TypeError: Cannot read properties of undefined (reading '$router')**

My code:

login: function () {
      var data = JSON.stringify({
        userName: "8801714015073",
        password: "123456",
      });

      var config = {
        method: "post",
        url: "http://192.168.8.14:8080/api/v1/auth/login",
        headers: {
          "Content-Type": "application/json",
        },
        data: data,
      };

      this.$axios(config)
        .then(function (response){
          console.log(JSON.stringify(response.data));
          if (response) {
            this.$router.push({ name: "Home" });
          }
        })
        .catch(function (error) {
          console.log(error);
        });
}
alprazolam
  • 111
  • 1
  • 14

0 Answers0