From fb5eb06bdd7f7a36a73a6f844006bc66c1b545e1 Mon Sep 17 00:00:00 2001 From: Mateja Date: Sat, 24 Jul 2021 20:19:10 +0200 Subject: Fetch products inside Vuex and display them using `ProductCard` components. --- client/src/store/index.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'client/src/store/index.js') diff --git a/client/src/store/index.js b/client/src/store/index.js index 5f05f19..d2fe9b7 100644 --- a/client/src/store/index.js +++ b/client/src/store/index.js @@ -1,11 +1,26 @@ -import { createStore } from 'vuex' +import {createStore} from 'vuex' +import axios from 'axios'; export default createStore({ state: { + products: [] + }, + getters: { + getProducts(state) { + return state.products; + } }, mutations: { + setProducts(state, products) { + state.products = products; + } }, actions: { + async pullProducts(context) { + await axios.get(`${process.env.VUE_APP_ROOT_API}/products`) + .then(response => context.commit('setProducts', response.data)) + .catch(error => console.error(error)); + } }, modules: { } -- cgit v1.2.3