W
W
wakenby2021-01-17 19:54:01
Vue.js
wakenby, 2021-01-17 19:54:01

Vuex when are mutations and when are actions?

Do I understand correctly that mutations are only for changing the state, and there should not be any logic. And in actions, all the logic that can be, including calls to the backend.

Or can there be logic in mutations that does not apply to requests to the server, and actions need to be used only when there is a request to the backend?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Valery Voronkov, 2021-01-17
@wakenby

In general, it is understood as follows: if you have any asynchronous requests, then there should be a bunch - action - mutation. If you just have a state update, then use a mutation. There is also a small note: even if you do not have asynchronous operations, but you need to perform 2 or more mutations, it is better to do this in an action.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question