降低状态值时,Vuex状态未更新

时间:2019-01-10 05:45:35

标签: javascript vue.js vuex

我正在尝试使用vuex更新状态,我的代码如下

动作

    async SET_DISTANCE_DURATION({ commit }, data) {
      commit("DURATION_DISTANCE", data);
    },

静音

    DURATION_DISTANCE(state, res) {
      state.prevDuration = state.Duration;
      state.Distance = res.distance;
      state.Duration = res.duration;
    },

状态

      Duration: null,

我面临的问题是当我增加持续时间而没有问题时,但是当我尝试减少持续时间时,我传递的值达到MUTATION但在状态内未得到更新,

我的持续时间分配

    current_total = current_total + temp2;
        let da = { distance: total_distance, duration: current_total 
       };
    this.$store.dispatch("SET_DISTANCE_DURATION", da);

我减少了持续时间分配

        current_total = current_total - removed_duration;
    let da = { distance: total_distance, duration: current_total };
    this.$store.dispatch("SET_DISTANCE_DURATION", da);

0 个答案:

没有答案