aboutsummaryrefslogtreecommitdiff
path: root/client/src/store
diff options
context:
space:
mode:
authorMateja <mail@matejamaric.com>2021-07-24 20:19:10 +0200
committerMateja <mail@matejamaric.com>2021-07-24 20:19:10 +0200
commitfb5eb06bdd7f7a36a73a6f844006bc66c1b545e1 (patch)
tree8554abca41ff7a628bdf613f26c579f8203abb61 /client/src/store
parent72016342cbb70ddc5d7288b80baf0571bb72a8f6 (diff)
downloadmevn-ecommerce-fb5eb06bdd7f7a36a73a6f844006bc66c1b545e1.tar.gz
mevn-ecommerce-fb5eb06bdd7f7a36a73a6f844006bc66c1b545e1.zip
Fetch products inside Vuex and display them using `ProductCard`
components.
Diffstat (limited to 'client/src/store')
-rw-r--r--client/src/store/index.js17
1 files changed, 16 insertions, 1 deletions
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: {
}