I have a long api call in my vuex store and if I change the route before it's finished and dispatch the same action from another page with a quicker api call the first call will eventually overwrite the second call. The action looks like this:
async getData({ commit }, payload) {
try {
const params = {...};
const res = await axios.get(`/data`, {
params,
});
if (res.status === 200) {
commit("setData", res.data);
}
} catch (error) {
commit("setError", error.response);
}
},
Is there a way to prevent this from happening?