[Vuejs]-Getter does not consistently retrieve data from Vuex

0👍

You have two computed sections in your component. You’ll need to combine them, something like:

computed: {
    ...mapGetters(['allDrafters']),
    minutes() {
        const minutes = Math.floor(this.totalTime / 60);
        return this.padTime(minutes);
    },
    seconds() {
        const seconds = this.totalTime - (this.minutes * 60);
        return this.padTime(seconds);
    }
}

I suggest using an IDE and/or linter to detect such problems.

0👍

Your mutation property setDrafters is a arrow function that is returning something inconsistent: (state.drafters) = drafters, because haven’t brackets that is equivalent to write return, you should do it with brackets to execute the function body without return nothing, try with:

const mutations = {
  setDrafters: (state, drafters) => {
    state.drafters = drafters
  }
};

For example in:

const getters = {
    // Get the drafters array
    allDrafters: (state) => state.drafters
};

There you are returning state.drafters and it’s ok, but in the mutation you don’t want return value, u want execute the function body to assign.

Leave a comment