Purpose:Allow the state data managed in vuex to be stored locally at the same time. You can avoid the need for your own storage.
1) First: We need to install a vuex plug-in vuex-persistedstate to support vuex state persistence. npm i vuex-persistedstate 2) Then: create a modules file in the src/store folder, and create user.js and cart.js under modules src/store/modules/user.js // User module export default { namespaced: true, state () { return { // User information profile: { id: '', avatar: '', nickname: '', account: '', mobile: '', token: '' } } }, mutations: // Modify user information, payload is the user information object setUser (state, payload) { state.profile = payload } } } 3) Next: Import the user module in src/store/index.js. import { createStore } from 'vuex' import user from './modules/user' export default createStore({ modules: user } }) 4) Finally: Use the vuex-persistedstate plugin for persistence import { createStore } from 'vuex' +import createPersistedstate from 'vuex-persistedstate' import user from './modules/user' export default createStore({ modules: user }, + plugins: [ + createPersistedstate({ + key: 'erabbit-client-pc-store', + paths: ['user'] + }) + ] }) Notice:
Summarize:
This is the end of this article about how to use the vuex third-party package to implement data persistence. For more relevant vuex data persistence content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: How to choose the right MySQL datetime type to store your time
>>: Summary of MySQL database usage specifications
What is routing? Routing refers to the activity o...
Table of contents Cycle comparison usage Summariz...
This article records the installation and configu...
JSONObject is just a data structure, which can be...
Method 1: Command line modification We only need ...
I used vue and bootstrap to make a relatively sim...
Preface In the past, the company used the 5.7 ser...
#!/bin/bash #Download SVN yum -y install subversi...
This article shares the specific code of js to im...
First, clarify a few concepts: JDBC: Java databas...
How can you find the location of the configuratio...
The idea of using token for login verification ...
1. TCP Wrappers Overview TCP Wrappers "wraps...
When joining a Windows 2008 server subdomain to a...
Table of contents 1. Problem Description 2. Probl...