'How to make multiple commits Vuex?
after receiving the data from the request, I try to transfer them to the store. but it is not possible to transfer everything at once, only one at a time. how to solve this problem?
async loadFines({ commit }, payload) {
commit('setIsTableLoading', true);
try {
const {
data: {
data: fines,
meta: pagination,
query: backendQuery,
},
} = await this.$axios.get('/fines', { params: payload });
commit('setFinesList', fines);
commit('setPagination', pagination);
commit('setBackendQuery', backendQuery);
} catch (error) {
console.log(error);
} finally {
commit('setIsTableLoading', false);
}}
how to make those 3 commits properly?
export const mutations = {
setFinesList(state, payload) {
state.finesList = payload
},
setIsTableLoading(state, payload) {
state.isTableLoading = payload;
},
setPagination(state, payload) {
state.pagination = payload;
},
setLabels(state, payload) {
state.labels = payload;
},
setBackendQuery(state, payload) {
state.backendQuery = payload;
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|