1.vuex 状态持久化插件 —— vuex-persistedstate

  1. npm install --save vuex-persistedstate

2.在vuex的index.js文件中

  1. import Vue from "vue";
  2. import Vuex from "vuex";
  3. import createPersistedState from 'vuex-persistedstate'

3.使用持久化插件

  1. export default new Vuex.Store({
  2. state: {
  3. car: []
  4. },
  5. mutations: {
  6. },
  7. getters: {
  8. },
  9. actions: {},
  10. modules: {},
  11. plugins: [createPersistedState()]
  12. });