sourcecode

Nuxt JS vuex에서 Vue 라우터를 사용하여 리디렉션

copyscript 2022. 8. 7. 16:47
반응형

Nuxt JS vuex에서 Vue 라우터를 사용하여 리디렉션

앱의 일부로 로그인/등록 시스템을 구축하고 있습니다.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 기능을 유지하고 싶습니다.

다음 두 가지 방법이 있습니다.

  1. $nuxt.$router.push행동 중에
  2. 통과하다this.$router.push필요에 따라 전화를 걸 수 있습니다.

이게 도움이 됐으면 좋겠다.

언급URL : https://stackoverflow.com/questions/57857559/redirect-using-vue-router-in-nuxt-js-vuex

반응형