Added state mutations
This commit is contained in:
parent
f5c59d3a75
commit
0c62aa49c6
1 changed files with 27 additions and 1 deletions
28
src/store.js
28
src/store.js
|
|
@ -15,7 +15,8 @@ export default new Vuex.Store({
|
||||||
available: true,
|
available: true,
|
||||||
waiting: false,
|
waiting: false,
|
||||||
error: '',
|
error: '',
|
||||||
apiConfig: {}
|
apiConfig: {},
|
||||||
|
apiState: {}
|
||||||
},
|
},
|
||||||
|
|
||||||
mutations: {
|
mutations: {
|
||||||
|
|
@ -38,6 +39,9 @@ export default new Vuex.Store({
|
||||||
},
|
},
|
||||||
commitConfig(state, configData) {
|
commitConfig(state, configData) {
|
||||||
state.apiConfig = configData;
|
state.apiConfig = configData;
|
||||||
|
},
|
||||||
|
commitState(state, stateData) {
|
||||||
|
state.apiState = stateData;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -81,6 +85,28 @@ export default new Vuex.Store({
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
updateState(context, uri=`${context.getters.uri}/state`) {
|
||||||
|
axios.get(uri)
|
||||||
|
.then(response => {
|
||||||
|
context.commit('commitError', '');
|
||||||
|
context.commit('commitState', response.data);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
var errormsg = '';
|
||||||
|
if (error.response) {
|
||||||
|
errormsg = `${error.response.status}: ${error.response.data}`
|
||||||
|
console.log(errormsg)
|
||||||
|
} else if (error.request) {
|
||||||
|
errormsg = `${error.message}`
|
||||||
|
console.log(errormsg)
|
||||||
|
} else {
|
||||||
|
errormsg = `${error.message}`
|
||||||
|
console.log(errormsg)
|
||||||
|
}
|
||||||
|
context.dispatch('errorState', errormsg);
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
resetState(context) {
|
resetState(context) {
|
||||||
context.commit('changeWaiting', false);
|
context.commit('changeWaiting', false);
|
||||||
context.commit('changeConnected', false);
|
context.commit('changeConnected', false);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue