[Vuejs]-How to return filtered array with vuex getters?

0👍

I’ve found the solution. The right way to call VUEX getters with params should be this.$store.getters.yourGetter()(params) or with …mapGetters. The main point that the getters with params return function and you can pass params in it.
For example how it works

getter:

getCities: state => region => {
    return state.cities.filter(city => city.region === region);
}

import and call:

methods: {
...mapGetters('location', [ 'getCities' ]),
test(params){
  console.log(this.getCities()(params))
}
}

0👍

You can import mapGetters or access the store object through this.$store.getters.getCities(a)

you can read more here:

https://vuex.vuejs.org/guide/getters.html#property-style-access

Leave a comment