使用Vue.js单击按钮后如何加载另一个组件

时间:2017-06-14 19:12:27

标签: vuejs2 vue-router

我正在创建一个应用程序,但是,我希望当我单击Signup时,register()执行并返回一个我希望路由到登录路径的promise。

我没有留在同一个注册页面,而是想要路由到登录页面

register(){

  axios.post('url', {

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

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

1 个答案:

答案 0 :(得分:2)

在路由器上使用push()

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

Vue-router有programmatic navigation