Service scenario: The state data in vuex is stored in localStorage. After the page is refreshed, the state data is released by the browser and the use of VuexPersistence is recorded:
1. Download dependencies
npm install --save vuex-persist
Copy the code
2. Store file index.js to import and use
import VuexPersistence from 'vuex-persist'
Copy the code
// Const vuexLocal = new VuexPersistence({storage: window.localstorage})Copy the code
Export default new vuex. Store({...... plugins: [vuexLocal.plugin] })Copy the code
Direct copy use, do not need to change any name.