Home > Article > Web Front-end > There are several ways to implement vue's cache
Vue has 4 ways to cache data: 1. Using localStorage, the syntax "localStorage.setItem(key, value)"; 2. Using sessionStorage, the syntax "sessionStorage.setItem(key, value)"; 3. Install and reference the storage.js plug-in, and use the plug-in for caching; 4. Use vuex, which is a state management mode specially developed for Vue.js applications.
The operating environment of this tutorial: windows7 system, vue3 version, DELL G3 computer.
Several ways to implement caching in vu:
* localStorage
window.localStorage.setItem(key,value) window.localStorage.getItem(key)
* sessionStorage
window.sessionStorage.setItem(key,value) window.sessionStorage.getItem(key)
The difference between localStorage and sessionStorage
https://blog.csdn.net/qq_31741481/article/details/88054069
Usage method:
import storage from 'store' // Store current user store.set('user', { name:'Marcus' }) // Get current user store.get('user') // Remove current user store.remove('user') // Clear all keys store.clearAll() // Loop over all stored values store.each(function(value, key) { console.log(key, '==', value) })
Tested, the default is stored in localStorage
store.js contains Various storage solutions have been provided. For example, in some scenarios where localStorage fails, cookieStorage.js can be used. Master it and you can basically catch all caching solutions in one go.
vue.js Tutorial"]
The above is the detailed content of There are several ways to implement vue's cache. For more information, please follow other related articles on the PHP Chinese website!