Home  >  Article  >  A brief discussion on the problem of vuex data caching

A brief discussion on the problem of vuex data caching

little bottle
little bottleforward
2019-04-30 10:52:375466browse

This article mainly talks about the data caching problem of vuex. The tabs in the page use vuex for data storage. When the route is switched, the tabs are added and rendered. When the page is refreshed, the data stored in the store will be initialized and become empty. How to solve this situation? ? Let’s find out with the editor.

A brief discussion on the problem of vuex data caching

Description: The tabs in the page use vuex for data storage. When switching routes, the tabs are added and rendered.
Problem: When the page is refreshed, it is stored in The data in the store will be initialized and become empty
Solution: The original idea was to use local cache for data storage, but it didn't feel too convenient, so I came up with vuex-along. I won't say much, let's go to the code

A brief discussion on the problem of vuex data caching
Introduce vuex-along
The array stored in the watch() method is where you want to save the data. The default is to cache all data, but some are It is not needed, you can set it inside
watchSession() is similar to watch() storage, but warchSession is stored in the session. The difference is that the data stored by the watch() method will not be lost when the browser is closed. WatchSession, close Browser data will be lost
onlySession() method is to close the current page and the data will be lost

Related tutorials:vue video tutorial


The above is the detailed content of A brief discussion on the problem of vuex data caching. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete