Difference between vuex and localStorage/sessionStorage

1. The most important difference: vuex is stored in memory, and localstorage is stored locally as a file

2. Application scenario: vuex is used for passing values ​​between components, and localstorage is mainly used for passing values ​​between different pages.

3. Persistent: The value stored by vuex will be lost when the page is refreshed, but not by localstorage.

Note: Many students think that localstorage can replace vuex, which is true for unchanged data,
but when two components share a data source (object or array), if one of the components changes the data source, I hope the other component will respond . When it should change, local storage cannot do it.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325832979&siteId=291194637