add a module store to deal with api data and calls and maybe save data to avoid api recalls

This commit is contained in:
Axolotle 2020-07-16 16:07:54 +02:00
parent 55fe70ab33
commit ea51885361
2 changed files with 25 additions and 1 deletions

View file

@ -0,0 +1,22 @@
import api from './api'
export default {
state: () => ({
domains: undefined
}),
mutations: {
'SET_DATA' (state, { key, data }) {
state[key] = data
}
},
actions: {
async 'FETCH' ({ commit }, uri) {
return api.get('/' + uri).then(data => {
commit('SET_DATA', { data: data[uri], key: uri })
})
}
},
getters: {
}
}

View file

@ -1,6 +1,8 @@
import Vue from 'vue'
import Vuex from 'vuex'
import dataStore from '@/helpers/dataStore'
Vue.use(Vuex)
export default new Vuex.Store({
@ -18,7 +20,6 @@ export default new Vuex.Store({
}
},
'YUNOHOST_INFOS' (state, data) {
console.log('version changed', data)
state.yunohostInfos = data
}
},
@ -26,5 +27,6 @@ export default new Vuex.Store({
actions: {
},
modules: {
data: dataStore
}
})