我想在logout
上清除用户数据,因此从auth
模块我dispatch
进行了一个在模块ride
中定义的操作,但出现错误:
[vuex] unknown local action type: clearUserData, global type: auth/clearUserData
这是我的代码:
export const namespaced = true
export const mutations = {
clearAuthData(state){
state.apiToken = null
state.signedIn = false
}
}
export const actions = {
logout({ commit, dispatch }) {
commit('clearAuthData'))
dispatch('ride/clearUserData', { root: true })
}
}
export const namespaced = true
export const state = {
data: []
}
export const mutations = {
CLEAR_USER_DATA(state){
state.data = []
}
}
export const actions = {
clearUserData({ commit }) {
commit('CLEAR_USER_DATA')
}
}
import * as auth from './modules/auth'
import * as ride from './modules/ride'
Vue.use(Vuex)
export default new Vuex.Store({
state: {
loading: false
},
modules: {
auth,
ride
}
})
我在做什么错了?
答案 0 :(得分:3)
您的usage of dispatch()
错误地传递了 m1.insert(pair<char,string>('A',"def"));
m1.insert(pair<char,string>('B',"ghi"));
m1.insert(pair<char,string>('C',"jkl"));
作为 2nd 参数,该参数专用于有效负载。选项应为第3个:
{ root: true }
答案 1 :(得分:1)
如果没有要传递的有效负载,则需要将第二个参数作为null
发送,如下所示:
dispatch('ride/clearUserData', null, { root: true })