[Vuejs]-Dynamic store value in Vuex

1👍

You can make use of getter which holds your logic for listSum and can be used in components

export default {
    namespaced: true,
    state: {
      my_list_values: [10,9,10],
    }
    getters: {
      listSum (state) {
        //logic to sum values
      }
  }
}

You can use this getter anywhere in your components as below

import { mapGetters } from 'vuex'

 computed: {
    ...mapGetters([
      'listSum',
      // ...
    ])
  }

OR

this.$store.getters.listSum

For Ref : Getters

Leave a comment