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
Install Make sure your user has permission to ins...
Table of contents 1. Overview 2. Memory Managemen...
Example: tip: This component is based on vue-crop...
webkit scrollbar style reset 1. The scrollbar con...
Table of contents Preface The difference between ...
Experimental environment A minimally installed Ce...
This article shares the specific code of Vue.js t...
Being an operation and maintenance engineer is a ...
In Linux operation and configuration work, dual n...
You may already know that the length 1 of int(1) ...
Readonly and Disabled both prevent users from cha...
Tomcat is widely known as a web container. It has...
See the effect first Implementation Code <div ...
Table of contents What does the COUNT function do...
Table of contents Solution Analysis slice Resume ...