Learn Vue JS course Learn Javascript and Vue JS Learn VueJS course Learn VueJS Tutorial
Learn Vue.js with Vue School #1 SOURCE OF VUE.JS KNOWLEDGE

Vuex for Everyone

Dynamic Vuex Getters

In this Vue.js tutorial, we’ll look into how we can use higher order functions to create dynamic getters in Vuex. Dynamic getters allow us to pass arguments to a getter. This is particularly useful if you want to query your store.

A common use case is to create a getter to find an item in the state using its id.

getProductById (state, getters) {
    return id => {
        return state.products.find(product => product.id === id)
    }
}