aboutsummaryrefslogtreecommitdiff
path: root/client/src/store/index.js
blob: d2fe9b7886f9d3e9e7e48f1d9a743f475585fa6f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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: {
  }
})