I am developing a CRUD application to show user-list. As an admin, the user list is shown with edit & delete icons. Once the user is deleted by dispatching deleteUser action, the user-list should be re-fetched to reflect updated list of users.
actions: {
fetchUsers(context) {
axios.get("/get/user").then(function(response) {
context.commit("SET_USERS", response.data);
});
},
deleteUser(context,payload) {
axios.delete("/delete/user",).then(function(response) {
if(response.status == 200) {
//Refresh the user list.
//HOW TO call "fetchUsers" from here.?
}
})
}
}
So I need to call fetchUsers action after delete user successful.
What is the best way to achieve this? Copying the code would help but it's against DRY principle. Delete is an example but there could be several actions like edit which would need to call fetchUsers again.
Kindly provide inputs.
Regards Robin.