[Vuejs]-A getter I made in vuex store.js is getting errors

0👍

Instead of attempting to access the loadedProducts via store, instead access it through the getters themselves. The docs on getters provide an example of accessing other getters within a getter via the second argument.

Getters will also receive other getters as the 2nd argument

loadedProduct (state, getters) {
  return (productId) => {
    return getters.loadedProducts.find((product) => {
      return product.partNumber === productId
    })
  }
}

Be sure you are setting reasonable defaults for your store properties such as an empty array for products.

Hopefully that helps!

Leave a comment