[英]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.