【发布时间】:2017-02-17 09:23:16
【问题描述】:
我无法让我的承诺在商店工作。
我通过一个动作调用突变,这似乎工作正常。
export const location = {
state: {
x: 0,
y: 0,
z: 0,
extent: [],
epsg: 'EPSG:3857'
},
mutations: {
setLocation(state, payload) {
// mutate state
console.log("Commit");
state.x = payload.x;
state.y = payload.y;
console.dir(state); //this does return the mutated state.
}
},
actions: {
setLocation(context, payload) {
console.dir(payload);
context.commit('setLocation', payload);
}
},
getters: {
mapLocation(state) {
return state
}
}
}
动作被导入到我的组件中:
methods: {
...mapActions(['setLocation']),
然后调用:
var location = {
x: data[0],
y: data[1]
}
this.setLocation(location);
这一切似乎都有效,但是当我查看 Vue 开发人员工具时,Vuex 基础状态保持不变,并且我有一个活动突变(setLocation)。我可以单击“全部提交”来提交有效的突变。
在我的组件中,我在 getter mapLocation 上使用了一个观察器,当我单击 Commit All 时会触发该观察器。
如何强制它提交到商店?
谢谢
【问题讨论】: