[英]vuex doesn't recognize the mutation
This is my vuex root store. 这是我的vuex根商店。
export default new Vuex.Store({ state: { account: {} }, mutations: { set_account(state,payload) { console.log("I AM INSIDE MUTATIONS", ) } }, actions: { setAccount({ commit }, payload) { return new Promise((resolve, reject) => { commit(set_account, payload) resolve() }) } }, plugins: [vuexLocal.plugin], modules: { auth, update } });
Here after the set account action I commit set_account
mutation. 在设置帐户操作之后,我提交了
set_account
变异。 But it says, 但它说,
set_account is not defined
set_account未定义
Why could this happen? 为什么会这样?
Try using commit()
with type , the first argument, being a string equal to 'set_account'
, the name of the respective action function name: 尝试使用带有类型的
commit()
,第一个参数是一个等于'set_account'
的字符串,相应的动作函数名称的名称:
export default new Vuex.Store({
state: {
account: {}
},
mutations: {
set_account(state,payload) {
console.log("I AM INSIDE MUTATIONS", )
}
},
actions: {
setAccount({
commit
}, payload) {
return new Promise((resolve, reject) => {
commit('set_account', payload)
resolve()
})
}
},
plugins: [vuexLocal.plugin],
modules: {
auth,
update
}
});
From the Vuex documentation for commit: 从提交的Vuex 文档 :
commit(type: string, payload?: any, options?: Object)
commit(type:string,payload?:any,options?:Object)
type
, the first argument should be a string, which in this case would need to match the function name of set_account
. type
,第一个参数应该是一个字符串,在这种情况下需要匹配set_account
的函数名。 Without it being a string, it's attempting to evaluate the expression set_account
which is effectively undefined in the current execution context. 如果没有它是一个字符串,它会尝试计算表达式
set_account
,它在当前执行上下文中实际上是未定义的。
Hopefully that helps! 希望这有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.