itsource

Vue.js vuex 모듈 내보내기/가져오기 실패

mycopycode 2022. 8. 16. 23:38
반응형

Vue.js vuex 모듈 내보내기/가져오기 실패

Vuex 모듈을 사용하려고 합니다만, 정상적으로 동작하고 있지 않습니다.디스패치하려고 하는 기존의 조작이 표시됩니다.

store/index.displaces

import Vue from 'vue'
import Vuex from 'vuex'
import * as getters from '@/store/getters'
import { state, actions, mutations } from '@/store/root'
import authentication from '@/store/modules/authentication'

Vue.use(Vuex)

const store = new Vuex.Store({
  strict: process.env.NODE_ENV !== 'production',
  state,
  actions,
  mutations,
  getters,
  modules: {
    authentication
  }
})

export default store

store/displicate/authentication을 실행합니다.js

import * as types from '@/store/mutation_types'
import firebase from 'firebase'

const authentication = {
  namespaced: true,
  state: {
    user: JSON.parse(localStorage.getItem('user')) || null,
    account: JSON.parse(localStorage.getItem('account')) || null
  },
  actions: {
    signUserUp ({commit}, payload) {
     ...
    },
    signUserIn ({commit}, payload) {
     ...
    },
    setUser ({commit}, newUser) {
      console.log('STORE ACTION setUser: ', newUser)
      commit(types.SET_USER, newUser)
    },
    setAccount ({commit}, newAccount) {
     ...
    },
    logout: context => {
     ...
  },
  mutations: {
   ...
  }
}

export default authentication

main.discloss.main.discloss.

store.dispatch('setUser', null) // <==  [vuex] unknown action type: setUser

모듈 선언에 문제가 있습니까?

사용하고 있다namespacedmodule, 액션명에 네임스페이스를 포함해야 합니다.

store.dispatch('authentication/setUser', {});

다른 이름 지정 모듈에서 액션을 디스패치하는 경우{root: true}파라미터:

dispatch('authentication/users', {}, { root: true });

언급URL : https://stackoverflow.com/questions/51346178/vue-js-export-import-vuex-module-failing

반응형