programing

라우터의 getter에서 데이터를 가져올 수 없습니다.[Vux 퀘이사]

minecode 2022. 8. 18. 22:55
반응형

라우터의 getter에서 데이터를 가져올 수 없습니다.[Vux 퀘이사]

라우터에서 날짜 양식을 가져오고 싶습니다.저희 매장에는 2개의 모듈이 있습니다.

export default function (/* { ssrContext } */) {
const Store = new Vuex.Store({
 modules: {
   customers,
   auth
 },
 namespaced: true,
 strict: process.env.DEV
})

  return Store
}

그리고 이것은 나의 auth/index.js 입니다.

import state from "./state";
import * as getters from "./getters"
import * as mutations from "./mutations"
import * as actions from "./actions"

export default {
 namespaced: true,
 state,
 mutations,
 actions,
 getters
}

사용자가 인증되었는지 확인하고 싶기 때문에 컴포넌트로 이동하기 전에 확인하고 싶습니다.

  {
    path: '',
    component: () => import('pages/Index.vue'),
    beforeEnter: ifAuthenticated()
  },

router/index.js에서 기능을 선언합니다.

export function ifAuthenticated(to, from, next){
console.log(store.auth); //undefined
if (store.auth.getters.isAuthenticated) {
  next();
  return;
}
next("/login");
};

getters to return value 또는 auth module 스토어 호출 방법

즉, 다음과 같습니다.

this.$store.getters['auth/isAuthenticated']

시도해 볼 수 있는 몇 가지 가능성이 있습니다.먼저 이 답을 살펴봅니다(다른 vuex 모듈에서 getter에 액세스하는 방법?).

난 노력하고 싶다:

this.$store.getters.isAuthenticated()
store.getters.isAuthenticated()
// don’t forget the ()

그런 다음 Root Getters를 추가하고 동일한 부분을 다시 테스트합니다.그래도 작동하지 않으면 네임스페이스를 사용해 보십시오(vuex의 모듈 네임스페이스란 정확히 무엇입니까).

store.getters[‘auth/isAuthenticated’]

또는 스토어에서 authGetters를 사용하여 열거형을 설정해 볼 수도 있습니다.

export enum authGetters {
  IS_AUTHENTICATED = 'isAuthenticated'
}

store.getters[authGetters.IS_AUTHENTICATED]

언급URL : https://stackoverflow.com/questions/61613261/cant-get-data-from-getters-in-router-vuex-quasar

반응형