- 如何更新全局变量?
- 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
},
})
);