Artwell
Artwell

Reputation: 1

How to load a another component after clicking a button using Vue.js

I am creating an app, however, I want that when I click Signup, register() executes and upon return of a promise I want to route to the login route.

Instead of staying on the same signup page, I want to route to the login page

register(){

  axios.post('url', {

    username: this.username,
    password:this.password
  })
  .then(function (response) {
    console.log(response);

  })
  .catch(function (error) {
    console.log(error);
  });

Upvotes: 0

Views: 2057

Answers (1)

Theo
Theo

Reputation: 2809

Use push() on the router.

.then(function (response) {
  console.log(response);
  this.$router.push('login');
})

Vue-router has programmatic navigation.

Upvotes: 2

Related Questions