The difference between Vuex and localStorage

  1. The scope of action is different.
    The scope of action of Vuex is in the content of the application, which plays a role in managing the state of the application. The scope of localStorage is the web browser, which is used to store data in the browser.
  2. Different types of stored data
    The data type stored by Vuex can be any type. The data type stored in localStorage can only be a string, and the stored object needs to be processed with the stringify and parse methods of JSON.
  3. The size of the stored data is different.
    The size of the data stored by Vuex is limited by the size of the memory. The size of the stored data in localStorage is generally about 5MB.
  4. The way of data sharing is different.
    The data in Vuex is shared, and different components can share the same data state. The data in localStorage is independent, and different pages or windows cannot share the same data state.
  5. Permanent
    The value stored by vuex will be lost when the page is refreshed, localstorage will not.

Guess you like

Origin blog.csdn.net/qq_42816270/article/details/129889461