2017-06-14 303 views
0

我正在創建一個應用程序,但是,當我單擊Signup時,register()會執行並且在返回承諾時我想要路由到登錄路線。如何使用Vue.js單擊按鈕後加載另一個組件

而是住在同一註冊頁面上,我要路由到登錄頁面

register(){ 

    axios.post('url', { 

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

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

你使用'vue-router'嗎? – Bert

+0

@ BertEvans..Yes我正在使用vue-router – Artwell

回答

2

在路由器上使用push()

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

Vue-router有programmatic navigation

+0

我可以導出路由器,以便我可以在另一個組件中使用它嗎? – Artwell

+0

@Artwell $路由器可在* all *組件上使用。 – Bert

+0

@BertEvans是正確的。爲了回答你的問題,是的,你也可以將它導出到其他組件中使用。這裏是一個例子... https://github.com/theosherman/insulin-calculator/blob/master/src/router/index.js – Theo

相關問題