Подключаем api
This commit is contained in:
@@ -2,16 +2,19 @@ import Vue from 'vue';
|
||||
import Vuex from 'vuex';
|
||||
import createPersistedState from 'vuex-persistedstate';
|
||||
|
||||
import root from './root.js';
|
||||
import uistate from './modules/uistate';
|
||||
import config from './modules/config';
|
||||
|
||||
Vue.use(Vuex);
|
||||
|
||||
const debug = process.env.NODE_ENV !== 'production';
|
||||
|
||||
export default new Vuex.Store({
|
||||
export default new Vuex.Store(Object.assign({}, root, {
|
||||
modules: {
|
||||
uistate
|
||||
uistate,
|
||||
config
|
||||
},
|
||||
strict: debug,
|
||||
plugins: [createPersistedState()]
|
||||
});
|
||||
}));
|
||||
|
||||
38
client/store/modules/config.js
Normal file
38
client/store/modules/config.js
Normal file
@@ -0,0 +1,38 @@
|
||||
import miscApi from '../../api/misc';
|
||||
// initial state
|
||||
const state = {
|
||||
name: null,
|
||||
version: null,
|
||||
};
|
||||
|
||||
// getters
|
||||
const getters = {};
|
||||
|
||||
// actions
|
||||
const actions = {
|
||||
async loadConfig({ commit, state }) {
|
||||
commit('setApiError', null, { root: true });
|
||||
commit('setConfig', {});
|
||||
try {
|
||||
const config = await miscApi.loadConfig();
|
||||
commit('setConfig', config);
|
||||
} catch (e) {
|
||||
commit('setApiError', e, { root: true });
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
// mutations
|
||||
const mutations = {
|
||||
setConfig(state, value) {
|
||||
Object.assign(state, value);
|
||||
},
|
||||
};
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
getters,
|
||||
actions,
|
||||
mutations
|
||||
};
|
||||
@@ -1,6 +1,6 @@
|
||||
// initial state
|
||||
const state = {
|
||||
asideBarCollapse: false,
|
||||
asideBarCollapse: false,
|
||||
};
|
||||
|
||||
// getters
|
||||
@@ -11,15 +11,15 @@ const actions = {};
|
||||
|
||||
// mutations
|
||||
const mutations = {
|
||||
setAsideBarCollapse(state, value) {
|
||||
state.asideBarCollapse = value;
|
||||
},
|
||||
setAsideBarCollapse(state, value) {
|
||||
state.asideBarCollapse = value;
|
||||
},
|
||||
};
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
getters,
|
||||
actions,
|
||||
mutations
|
||||
namespaced: true,
|
||||
state,
|
||||
getters,
|
||||
actions,
|
||||
mutations
|
||||
};
|
||||
|
||||
25
client/store/root.js
Normal file
25
client/store/root.js
Normal file
@@ -0,0 +1,25 @@
|
||||
// initial state
|
||||
const state = {
|
||||
apiError: null,
|
||||
};
|
||||
|
||||
// getters
|
||||
const getters = {};
|
||||
|
||||
// actions
|
||||
const actions = {};
|
||||
|
||||
// mutations
|
||||
const mutations = {
|
||||
setApiError(state, value) {
|
||||
state.apiError = value;
|
||||
},
|
||||
};
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
getters,
|
||||
actions,
|
||||
mutations
|
||||
};
|
||||
Reference in New Issue
Block a user