vuex persistence
Solution:
import Vue from 'vue' import Vuex from 'vuex' //Introduce import persistedState from 'vuex-persistedstate' Vue.use(Vuex) export default new Vuex.Store({ state: { num: null, name: null }, mutations: getNum(state, val) { state.num = val }, getName(state, val) { state.name = val } }, //Configure plugins: [ persistedState({ //By default, localStorage is used to solidify data. SessionStorage can also be used. The configuration is the same: storage: window.localStorage, reducer(val) { return { // Only store the value num in state: val.num, name: val.name } } }) ] }) I assign values to variables in the state of vuex in the Home component created(){ this.$store.commit('getNum',3) this.$store.commit('getName','胡歌') }, Reference in H component <template> <div> {{$store.state.num}} {{$store.state.name}} </div> </template> In this way, when refreshing the H component, the variables in $store.state will not change. In fact, they are automatically stored in the local storage. SummarizeThis article ends here. I hope it can be helpful to you. I also hope you can pay more attention to more content on 123WORDPRESS.COM! You may also be interested in:
|
<<: How to use CSS to pull down a small image to view a large image and information
>>: The leftmost matching principle of MySQL database index
This article uses examples to illustrate the sear...
Glass Windows What we are going to achieve today ...
Why do we need to build a nexus private server? T...
1. Custom text selection ::selection { background...
The form code is as shown in the figure. The styl...
Table of contents Preface cause Phenomenon why? A...
1. Delete node Execute kubectl delete node node01...
1. Overview of SQLException When an error occurs ...
Effect Preview Ideas Scroll the current list to t...
Phenomenon The system could compile the Linux sys...
When designing table structures, numeric types ar...
In the web pages we make, if we want more people ...
Variables defined in SASS, the value set later wi...
1. Background In actual projects, we will encount...
This article introduces several methods of implem...