re: Explain Stores (Vuex) Like I'm Five VIEW POST

VIEW PARENT COMMENT VIEW FULL DISCUSSION
 

What a great answer!!! Thank you very much!.

Sorry for my english, I try to write the best I can.

I have a question. Maybe you just answered and I don't realized.

What's the difference between a store and a global service that I can access and get data? (Is the cardboard example?)

Thanks!

 

Your English is excellent.

Assuming the Vuex store and the global service are both local (no HTTP requests or anything), the differences are:

  • Vue knows about the Vuex store, so it can do change tracking on it. If something changes in the Vuex store, the Vue app can update computed properties and watchers and re-render the DOM where necessary. If something changes in a global service, Vue won't know about it.
  • A global service is mutable, so it's harder to track changes to it as the application runs. A Vuex store is immutable--every time you change the state, a new object is created to hold the data. This means you can find out what changed between one state and the next by comparing the objects.
  • Vuex stores have some extra functionality, like NPM packages and plugins that can help you organize your state or even persist it to LocalStorage automatically.

Excellent answer. Very clear for me!

Thank you very very much!

code of conduct - report abuse