import Vue from "vue";
import Vuex from "vuex";
import actions from "./actions";
import * as getters from "./getters";
import state from "./state";
import mutations from "./mutations";
import createPersistedState from 'vuex-persistedstate';
Vue.use(Vuex);

// store
const store = new Vuex.Store({
  getters,
  state,
  actions,
  mutations,
  plugins: [
    createPersistedState({
      // 当state中的值发生变化的时候出发reduce函数
      reducer(val) {
        console.log(val, 'createPersistedState')  // value值为当前state中的所有值对象
        // return什么，localstorage中的key值为vuex的value值就是什么，而且是实时与state中的值保持同步
        return {
          userInfo: val.userInfo,
          user_access_token: val.user_access_token
        }
      }
    })
  ]
});

export default store;