支付宝小程序 herculex 状态管理?

  1. 如何更新全局变量?
  2. mapMutationsToMethod: ['loadUserInfo'] 如何使用
import { GlobalStore } from 'herculex';

export default new GlobalStore({
   state: {
      userInfo: {},
      offsetTop: 0,
      offsetBottom: 0,
      scrollHeight: 0,
   },
   plugins: [], //'logger'
   mutations: {
      updateSystemInfo(state, payload) {
         state = Object.assign(state, payload);
      },

      updateUserInfo(state, payload) {
         state.userInfo = payload;
      },
   },
   actions: {
      async loadSystemInfo({ commit }, payload) {
         commit('updateSystemInfo', payload);
      },

      async loadUserInfo({ commit }, payload) {
         commit('updateUserInfo', payload);
      },
   },
});
import SystemInfo from './utils/tools/getSystemInfo';
import GlobalStore from './utils/store/globalStore';

App(
   GlobalStore({
      async onLaunch(options) {
         const systemInfo = SystemInfo.execute();
         // 如果更新 systemInfo 到 $global
      },
   })
);

index.js

import SystemInfo from '../../utils/tools/getSystemInfo';
import store from '../../utils/store/sharedStore';

Page(
   store.register({
      mapMutationsToMethod: ['loadUserInfo'],
      async onLoad(options) {
         // 如何使用 loadUserInfo 
      },
   })
);
阅读 229
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题