The difference between
1. The most important difference
- Vuex is stored in memory
- Localstorage, on the other hand, is stored locally as a file. Localstorage can only store string data, which requires JSON’s Stringify and parse methods to process.
Note: Reading memory is faster than reading hard disk.
2. Application scenarios
- Vuex is a state management mode developed specifically for vue.js applications. It uses centralized storage to manage the state of all components of an application and rules to ensure that the state changes in a predictable way. Vuex is used to transfer values between components.
- Localstorage is localstorage and is a method of storing data to a browser, typically when passing data across pages.
- Vuex can be responsive to data, but localStorage cannot.
3. The permanent
- The Vuex value will be lost when the page is refreshed, but localStorage will not.
Note: Many people think of LocalStorage as an alternative to Vuex. This is true for unchanging data, but when two components share a data source (object or array), Vuex is preferred if one component changes the data source and expects the other component to respond to the change. Loaclstorage can’t do that, and that’s the big difference.