Skip to content

Instantly share code, notes, and snippets.

@c0depanda
Last active January 6, 2019 04:47
Show Gist options
  • Save c0depanda/b969d59d1035dee93c0daa889633fd88 to your computer and use it in GitHub Desktop.
Save c0depanda/b969d59d1035dee93c0daa889633fd88 to your computer and use it in GitHub Desktop.

Revisions

  1. c0depanda revised this gist Jan 6, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion store.js
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,7 @@ export const store = new Vuex.Store({
    mutations: {
    // Add item to cart
    addItemToCart (state, payload) {
    state.cart.push[payload];
    state.cart.push(payload);
    },
    },
    })
  2. c0depanda created this gist Jan 6, 2019.
    28 changes: 28 additions & 0 deletions store.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    // import Vue
    import Vue from 'vue';
    // import Vuex
    import Vuex from 'vuex';

    // Install the Vuex plugin on vue
    Vue.use(Vuex);

    // create a Vuex store instance
    export const store = new Vuex.Store({
    state: {
    cart: ["bread", "rice", "beans", "turkey"]
    },

    getters: {
    // Fetch the total number of items in the cart
    totalNumberOfCartItems: state => {
    return state.cart.length;
    },
    },

    mutations: {
    // Add item to cart
    addItemToCart (state, payload) {
    state.cart.push[payload];
    },
    },
    })