Skip to content

Instantly share code, notes, and snippets.

@c0depanda
Created January 6, 2019 02:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c0depanda/9fde0a4878868a095dfd223885db8d2c to your computer and use it in GitHub Desktop.
Save c0depanda/9fde0a4878868a095dfd223885db8d2c to your computer and use it in GitHub Desktop.
// 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;
},
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment