index.js 629 B

1234567891011121314151617181920212223242526272829303132
  1. /*
  2. * @Author: 廖明明
  3. * @Date: 2022-03-31 16:36:19
  4. * @LastEditors: 廖明明
  5. * @LastEditTime: 2022-04-01 17:45:03
  6. * @Description:vuex入口文件
  7. */
  8. import Vue from "vue";
  9. import Vuex from "vuex";
  10. import user from "@/store/modules/user";
  11. Vue.use(Vuex);
  12. const myPlugin = (store) => {
  13. // 当 store 初始化后调用
  14. let vuexStorage = uni.getStorageSync("vuexStorage");
  15. if (vuexStorage) {
  16. store.replaceState(vuexStorage);
  17. }
  18. store.subscribe((mutation, state) => {
  19. uni.setStorageSync("vuexStorage", state);
  20. });
  21. };
  22. export default new Vuex.Store({
  23. modules: {
  24. user,
  25. },
  26. plugins: [myPlugin],
  27. });