diff options
author | Santo Cariotti <santo@dcariotti.me> | 2021-03-19 15:51:04 +0100 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2021-03-19 15:51:04 +0100 |
commit | 4410f2e46cbf961f2100038b53426bd07aebc4e9 (patch) | |
tree | 59bb661b4b15d04555b434db41a4cb9560da0cdc | |
parent | a686db800f50db4f6585fcdf1110873f577bfaeb (diff) |
feat: get all commits
-rw-r--r-- | src/store.js | 15 | ||||
-rw-r--r-- | src/views/Home.vue | 10 |
2 files changed, 25 insertions, 0 deletions
diff --git a/src/store.js b/src/store.js index 0e96ac7..9080bd0 100644 --- a/src/store.js +++ b/src/store.js @@ -8,9 +8,24 @@ export default new Vuex.Store({ api: process.env.VUE_APP_BACKEND_URL, commits: [], }, + get: { + commits: state => { + return state.commits + }, + }, mutations: { + load_commits: (state, value) => { + state.commits = value + }, }, actions: { + // Get all commits from the api backend + async get_commits({commit}) { + await fetch(`${this.state.api}/commit/`) + .then(async response => { + commit('load_commits', await response.json()); + }) + }, }, modules: { } diff --git a/src/views/Home.vue b/src/views/Home.vue index 55c3c08..28da86b 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -1,6 +1,8 @@ <template lang="pug"> main header-blue + b-container + h2 List of commits </template> <script> @@ -10,6 +12,14 @@ export default { name: "Home", components: { 'header-blue': HeaderBlue, + }, + mounted() { + this.$store.dispatch('get_commits'); + }, + computed: { + commits: () => { + return this.$store.get.commits; + } } } </script> |