[Vuejs]-Uncaught Error: [vuex] getters should be function but "getters.products" in module "prods" is []

0👍

I’ve discovered an answer to my question. In my store.js, I do not use createStore twice, but just once. That will resolve the problem:

import { createStore } from 'vuex';
const products = {
  namespaced: true,
  state() {
    return {
      allProducts: [
        {
          id: 'p1',
          image: "",
          title: 'Books',
          description: 'Books collection.',
          price: 20
        },
      ]
    };
  },
  getters: {
    products(state) {
      return state.allProducts;
    }
  }
}
const store = createStore({
  modules: {
    prods: products,
  },
});
export default store;

Leave a comment