Skip to content

Commit

Permalink
add store
Browse files Browse the repository at this point in the history
  • Loading branch information
jesuslerma committed Jul 13, 2017
1 parent f986e28 commit 6cc6b28
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/vuex/store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'

Vue.use(Vuex)

const state = {
categories: {
all: []
}
}

const getters = {
getAllCategories: state => state.categories.all
}

const mutations = {
setCategories (state, categories) {
state.categories.all = categories
},
selectCategory (state, category) {
category.selected = !category.selected
}
}
const actions = {
fetchCategories: ({ commit }) => {
var url = 'https://raw.githubusercontent.com/jesuslerma/vuejs101-guide/master/categories.json'
axios.get(url).then(function (response) {
commit('setCategories', response.data)
})
},
selectCategory({ commit }, category) {
commit('selectCategory', category)
}
}

const debug = process.env.NODE_ENV !== 'production'

export default new Vuex.Store({
state,
getters,
actions,
mutations,
strict: debug
})

0 comments on commit 6cc6b28

Please sign in to comment.