M
M
Michael2017-04-22 12:04:44
Vue.js
Michael, 2017-04-22 12:04:44

Vuex mutation on every request, which is better?

I am using Vuex. There is a need to support requests to a third-party service. But the fact is that there is a system object with each request, something like:

{
 type: 'system',
 package: 1
}

and with each request it should be incremented. Suppose I will store a variable in the root store and change it using a mutation, but how can I get rid of the need to call a mutation in each action. Is it possible to just call her with each request. It is supposed to use vue-resource for requests, but other solutions can be used.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Kulakov, 2017-04-22
@FFxSquall

Maybe you shouldn't store it in vuex. Store it in the object where all requests come from, i.e. for example, wrap vue-resource in your http module and increment there when called. If necessary, then additionally save to localStorage/localSession.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question