add vuex-persist
This commit is contained in:
@@ -1,3 +1,24 @@
|
||||
export default {
|
||||
import Vuex from 'vuex';
|
||||
import state from './state';
|
||||
import VuexPersist from 'vuex-persist'
|
||||
|
||||
}
|
||||
export default {
|
||||
install(Vue) {
|
||||
Vue.use(Vuex);
|
||||
|
||||
const vuexLocalStorage = new VuexPersist({
|
||||
key: 'vuex',
|
||||
storage: window.localStorage,
|
||||
reducer: ({ ...request }) => ({
|
||||
...request
|
||||
})
|
||||
})
|
||||
|
||||
const store = new Vuex.Store({
|
||||
state,
|
||||
plugins: [vuexLocalStorage.plugin]
|
||||
});
|
||||
|
||||
Vue.prototype.$store = store;
|
||||
},
|
||||
};
|
||||
|
||||
53
store/mutations.js
Normal file
53
store/mutations.js
Normal file
@@ -0,0 +1,53 @@
|
||||
export default {
|
||||
setState(state, object){
|
||||
state.request[object.attribute] = object.value
|
||||
},
|
||||
|
||||
addHeaders(state, value) {
|
||||
state.request.headers.push(value);
|
||||
},
|
||||
|
||||
removeHeaders(state, index) {
|
||||
state.request.headers.splice(index, 1)
|
||||
},
|
||||
|
||||
setKeyHeader(state, object) {
|
||||
state.request.headers[object.index].key = object.value
|
||||
},
|
||||
|
||||
setValueHeader(state, object) {
|
||||
state.request.headers[object.index].value = object.value
|
||||
},
|
||||
|
||||
addParams(state, value) {
|
||||
state.request.params.push(value);
|
||||
},
|
||||
|
||||
removeParams(state, index) {
|
||||
state.request.params.splice(index, 1)
|
||||
},
|
||||
|
||||
setKeyParams(state, object) {
|
||||
state.request.params[object.index].key = object.value
|
||||
},
|
||||
|
||||
setValueParams(state, object) {
|
||||
state.request.params[object.index].value = object.value
|
||||
},
|
||||
|
||||
addBodyParams(state, value) {
|
||||
state.request.bodyParams.push(value);
|
||||
},
|
||||
|
||||
removeBodyParams(state, index) {
|
||||
state.request.bodyParams.splice(index, 1)
|
||||
},
|
||||
|
||||
setKeyBodyParams(state, object) {
|
||||
state.request.bodyParams[object.index].key = object.value
|
||||
},
|
||||
|
||||
setValueBodyParams(state, object) {
|
||||
state.request.bodyParams[object.index].value = object.value
|
||||
},
|
||||
};
|
||||
19
store/state.js
Normal file
19
store/state.js
Normal file
@@ -0,0 +1,19 @@
|
||||
export default {
|
||||
request: {
|
||||
method: 'GET',
|
||||
url: 'https://reqres.in',
|
||||
path: '/api/users',
|
||||
label: '',
|
||||
auth: 'None',
|
||||
httpUser: '',
|
||||
httpPassword: '',
|
||||
bearerToken: '',
|
||||
headers: [],
|
||||
params: [],
|
||||
bodyParams: [],
|
||||
rawParams: '',
|
||||
rawInput: false,
|
||||
requestType: '',
|
||||
contentType: '',
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user