Solve the problem of vuex page refresh data loss

Generally, when the login is successful, user information and menu information need to be placed in vuex as global shared data. But when the page is refreshed, the data in vuex will be reinitialized, resulting in data loss. Because the data in vuex is stored in the running memory , when the page is refreshed, the page will reload the vue instance, and the data in vuex will be cleared.

Method 1: Save the data in vuex directly to the browser cache (sessionStorage, localStorage, cookie)
Method 2: Request remote data again when the page is refreshed to dynamically update the vuex data
Method 3: Request from the parent page to the background Remote data, and save the vuex data to sessionStorage before the page is refreshed (in case the requested data volume is too large and the returned data cannot be obtained when the page loads)

Guess you like

Origin blog.csdn.net/wsdshdhdhd/article/details/126571381