我正在尝试使用Vuex模块,但运行不正常,尝试分派它时出现未知动作...
store / 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
我的模块声明有什么问题吗?
答案 0 :(得分:2)
您正在使用kubectl get --all-namespaces=true svc | grep redis-master
模块,应该在操作名称中包括名称空间:
namespaced
更多
如果要从另一个命名空间模块中分派操作,则可能需要使用store.dispatch('authentication/setUser', {});
参数:
{root: true}