The difference between mutations and actions in Vuex, vuexmutations

Source: Internet
Author: User

The difference between mutations and actions in Vuex, vuexmutations

The difference between actions and mutations is not to solve the problem of competition,To use devtools to track status changes.

In fact, in vuex, actions is just a concept of atomicity. It is not necessary. In the end, it is just a function. you can do everything you want in it, as long as mutation is triggered. How to deal with asynchronous competition is the user's own business.

What vuex really limits you is that mutation must be synchronized (in redux, it is like CER must synchronously return to the next state ). The significance of synchronization is that after each mutation is executed, it can correspond to a new State (the same as CER), so that devtools can save a snapshot, then you can choose time-travel. If you open devtool to call an asynchronous action, you can clearly see when the mutation called by it is recorded, and you can immediately view their corresponding status.

Test:If an asynchronous operation is performed in mutation, a snapshot will be immediately printed in dev-tools. At this time, the asynchronous operation has not been completed, and the snapshot information is incorrect.

In the action, dev-tools will wait until the asynchronous operation is executed to print a snapshot of mutation, so that we can check the time-travel, view the changes in a mutation.

The differences between mutations and actions in Vuex above are all the content that I have shared with you. I hope you can give us a reference and support the help house.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.