M
M
myskypesla2018-07-17 14:25:34
Vue.js
myskypesla, 2018-07-17 14:25:34

How to change values ​​in state vuex correctly?

Vue.js application using Vuex.
Vuex store is like this:

state: {
  step: 'start',
},
mutations: {
  toggleStep(commit, value) {
    this.state.step = value;
  },
},
actions: {},

There is a Start.vue component, it contains a button:
<a href='#' @click.prevent='nextStep'>Следующий шаг</a>

The "nextStep" method, sends a value, for example:
nextStep() {
  this.$store.commit('toggle', 'login');
},

Accordingly, the value 'login' comes to state.step and everything is OK,
but someone said that it is bad practice to change the state directly through mutations.
Since all the same, it will be right to do in this situation and not only in it at all?

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