Home > Common Problem > body text

A brief discussion on the problem of vuex data caching

little bottle
Release: 2019-04-30 10:52:37
forward
5402 people have browsed it

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!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!