V
V
Vadim Sutormin2021-11-10 12:31:20
JavaScript
Vadim Sutormin, 2021-11-10 12:31:20

Why is the error "[vuex] do not mutate vuex store state outside mutation handlers." in the NUXT project?

There is a module in the Store, like this:

export const state = () => ({
  list: []
})

export const mutations = {
  addToListM(state, data) {
    state.list.push(data)
  }
}

export const getters = {
  getList: (state) => {
    return state.list
  }
}


In the component, a method that commits new data from the data component to the module state, after which it resets some data values ​​to its original state:
resultToList() {
      this.$store.dispatch('transportcalc/addToList', {params: this.params, indices: this.indices, result: this.result, description: ''})
      this.result = false
      this.indices = false
      this.volume = ''
      this.power = ''
    }


I get data from the Store via computed and then expand the table based on this data:
computed: {
    list: {
      get() {
        return this.$store.getters['transportcalc/getList']
      },
      set() {

      }
    }
  },


The problem is that after the first set of data in the Store is committed and I start changing the parameters in the Data component (specifically, changing the params), I get the error [vuex] do not mutate vuex store state outside mutation handlers. Where to dig, tell me?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question