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
#!/bin/bash #Download SVN yum -y install subversi...
Editor's note: This article is contributed by...
This article shares the specific code of JS to ac...
Error screenshot Can't find where the excepti...
Preface: With the continuous development of Inter...
1. HBase Overview 1.1 What is HBase HBase is a No...
1. Introduction to docker-maven-plugin In our con...
Part of the code: Copy code The code is as follow...
The nginx configuration file is mainly divided in...
This article mainly involves solutions to problem...
Let's take a look at the problem of VScode re...
The following are all performed on my virtual mac...
The spread operator allows an expression to be ex...
Table of contents 1. What is lazy loading of rout...
at at + time at 17:23 at> touch /mnt/file{1..9...