【问题标题】:vuex commit does not commit to storevuex commit 不提交到 store
【发布时间】: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 时会触发该观察器。

如何强制它提交到商店?

谢谢

【问题讨论】:

    标签: vue.js vuex


    【解决方案1】:

    好的,这实际上是一个非常简单的问题/疏忽。

    我没有在 DOM 中对我正在观察的计算属性进行任何建模,因此它从未更新过。

    所以解决方案就是使用 v-model="mapLocation" 来确保手表触发。

    【讨论】:

      猜你喜欢
      • 2014-03-11
      • 2019-06-13
      • 1970-01-01
      • 2019-08-08
      • 2016-02-14
      • 1970-01-01
      • 2021-09-23
      • 1970-01-01
      • 2021-07-09
      相关资源
      最近更新 更多