Skip to content

Instantly share code, notes, and snippets.

@lsbyerley
Last active February 1, 2018 10:07
Show Gist options
  • Save lsbyerley/1db1aa85b2ff76da2fbcc59cbd4cad0d to your computer and use it in GitHub Desktop.
Save lsbyerley/1db1aa85b2ff76da2fbcc59cbd4cad0d to your computer and use it in GitHub Desktop.
// store/index.js
const createStore = () => {
return new Vuex.Store({
state: {
counter: 0,
repos: []
},
actions: {
LOAD_REPOS: function({ commit }) {
axios.get('url').then((res) => {
commit('SET_REPOS', res.data)
})
}
},
mutations: {
SET_REPOS: (state, repos) => {
state.repos = repos
},
increment(state) {
state.counter++
}
}
})
}
// pages/index.vue
<script>
import { mapState } from 'vuex'
export default {
fetch ({ store }) {
store.dispatch('LOAD_REPOS')
},
computed: mapState([
'counter',
'repos'
]),
methods: {
increment () {
this.$store.commit('increment')
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment