When retrieving data from Vuex, in some cases the choice between using getters and access state directly is quite clear. For example:
count variable, accessing the state directly seems to make senseBut what about other cases where there is only a slight amount of logic required to retrieve a value? For example, what if I have a foo object in the root of my store, and:
Either of these needs could be met using a mapState function, but should I be using mapGetter instead? What's the difference?
Either of these needs could be met using a mapState function
True... but what happens if more than 1 component needs the "slightly altered" value? You'd end up with duplicate logic. In that case perform the "slight amount of logic" in a getter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With