I
I
Igor Bezlepkin2018-11-13 16:57:12
Vue.js
Igor Bezlepkin, 2018-11-13 16:57:12

How to track Vuex state change from Vue component?

Hey! There is vuex divided into modules. The messenger module has

const state = {
  messages: []
}

How to track changes in the messages array in the component?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
nvdfxx, 2018-11-14
@Bezlepkin

computed: {
    todos: () {
       return  this.$store.getters.getTodos
    }
}

create getters in store:
getters: {
    getTodos: state => state.todos
}

S
shmatuan, 2018-11-13
@shmatuan

https://vuex.vuejs.org/en/guide/modules.html

computed: {
  ...mapState('some/nested/module', {
    a: state => state.a,
    b: state => state.b
  })
},

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question