Why use vuex?

recently I tried to use vue as a project and used vuex to manage status, but I found a problem:
that is, the data in vuex is emptied after the page is refreshed, so basically all the data I store in vuex has to be saved in the browser once, so the question comes, why not just save the data in the browser and save it in vuex?

Mar.22,2021

unlike data storage, the main problem solved by Vuex is communication between different components to manage the data state of the current page.
since it is a state, it is not persistent, and data is automatically lost after the page is refreshed or closed.
if there are fewer components, you don't have to use Vuex at all.

moreover, there are many Vuex-based plug-ins that combine localStorage, sessionStorage, IndexDB, etc., to achieve the purpose of data persistence.


Vuex is not just for communication between different components. To use Vuex, you must first understand what the front-end state is.

imagine a scenario in which users fill in a lot of information when purchasing goods, and then need to fill in the address. Go to a new page to create an address, then go back to the original page and even the drop-down box that the user is asked to fill in is still there.

whether the drop-down box is open is a state.

when there is a business requirement, the status cannot be lost. Vuex can help you manage this state and then revert to the scene through Vue.

above is the scenario where Vuex should be used. There are several scenarios where Vuex is not required.

  • in this scenario described by the landlord himself, the data is one-time, and new data can be obtained from the server every time
  • non-business group prices for reuse, such as pop-up windows, forms, which should not be linked to Vuex
Menu