[英]Redirect using Vue Router in Nuxt JS vuex
我正在將登錄/注冊系統構建為應用程序的一部分。 我正在使用Firebase和Vuex處理身份驗證和數據庫信息。 我在Nuxt JS中有一些操作可以創建用戶,登錄並注銷他們。
我正在嘗試在用戶成功注冊后實現重定向/當他們單擊登錄時,我的代碼是:
export const actions = {
/*
* Create a user
*/
createUser ({commit}, payload) {
this.$fireAuth.createUserWithEmailAndPassword(payload.email, payload.password).then(function(firebaseUser) {
commit('setUser', payload)
}).catch(function(error) {
console.log('error logging in' + error)
});
},
/*
* Log a user into Beacon
*/
login ({commit}, payload) {
this.$fireAuth.signInWithEmailAndPassword(payload.email, payload.password).then(function(firebaseUser) {
commit('setUser', payload)
}).catch(function(error) {
console.log('error logging in' + error)
});
},
/*
* Sign a user out of Beacon
*/
signOut ({commit}) {
this.$fireAuth.signOut().then(() => {
commit('setUser', null)
}).catch(err => console.log(error))
}
}
我在Vue JS 2.6.10上使用Nuxt JS 2.9.2
我有幾個模塊。
我嘗試使用this.router.push('/')
和window.location.href
,但想保留SPA功能。
您有兩種方法可以做到:
$nuxt.$router.push
操作 this.$router.push
作為參數,然后在需要的地方調用。 希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.