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
Preface When it comes to database transactions, a...
Display different menu pages according to the use...
Phrase elements such as <em></em> can ...
Recently, when using element table, I often encou...
Are you still using rem flexible layout? Does it ...
MySQL DATE_ADD(date,INTERVAL expr type) and ADDDA...
Today I made a menu button. When you move the mous...
This article shares the specific code of vue+elem...
Table of contents $nextTick() $forceUpdate() $set...
Preface: This article refers to jackyzm's blo...
<br />Semanticization cannot be explained in...
background Today, I was browsing CodePen and saw ...
<br />What principles should be followed to ...
This article shares the simple process of install...
There are many XHTML tags: div, ul, li, dl, dt, d...