[Vuejs]-Where i should put dynamic and reactive parameter – in vue computed or vue store?

0👍

You will need to store the data in vuex and then access the getters in the computed method:

computed: {
  ...mapGetters(['topProducts'])
}

In your getters:

topProducts: state => state.topProducts

To sum up, you’ll need an action that will commit the mutation. Or even you can use the getters. Here’s an example:

computed: {
   ...mapGetters([
     'summingA',
     'summingB'
   ]),
   getTotal() {
    return this.summingA + this.summingB
   }
}

In your getters:

summingA: state => state.summingA,
summingB: state => state.summingB

0👍

In my humble opinion you should re-think a little bit more about how you designed this aspect so far. I mean you should not be in a scenario where your store contains duplicate data like this:

{ '1' : 
     {name: 'Apple', category: 'Fruits', 'sales': 50}, 
     {name: 'Apple', category: 'Fruits', 'sales': 50}
}

By principle the store serves as the single source of truth which makes it straightforward to locate a specific piece of state. This implicitly means it is not a good design to have duplicate entries within the store’s state. You should store the data before saving it into the store. Complying to this design principle would prevent you from dealing with questions like that one.

Leave a comment