[英]Vuex: Cannot pass state in mutation in module pattern. Commit mutation without axios
我想state
对我的mutations
。
我有像store.js
:
export const store = new Vuex.Store({
state: {
server: 'something'
},
modules: {
Product,
Cart
}
})
然后,在我的product.js
模块上。 我可以用getters
获得store
server
,但不能用于mutations
。 附言:我需要commit
不axios
..
export default{
state :{
abc: 'asdfasf'
},
getters :{
getServer : (state, getters, rootState) =>{
return rootState.server; //It works fine.
},
},
mutations :{
UPDATE(state,rootState){
console.log(state.getters.getServer); //this wont work
state.abc = rootState.serve; //something like this won't work
either
}
}
}
无法访问突变中的rootState
。 但是你可以在actions
做到这一点,然后调用突变来提交状态
actions: {
updateServer ({commit, rootState}) {
commit('UPDATE', rootState.serve)
}
},
mutations: {
UPDATE (state, payload){
state.abc = payload
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.