我正在尝试使用 Vuex 模块,但它运行不正常,我得到 uknown 动作试图调度它......
存储/index.js
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
存储/模块/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.js
store.dispatch('setUser', null) // <== [vuex] unknown action type: setUser
我的模块声明有什么问题?