29 lines
596 B
JavaScript
29 lines
596 B
JavaScript
|
import { initGlobalState } from 'qiankun';
|
|||
|
import { reactive } from 'vue';
|
|||
|
|
|||
|
const initialState = reactive({
|
|||
|
user: {
|
|||
|
name: 'admin',
|
|||
|
},
|
|||
|
menus: [],
|
|||
|
auths: [],
|
|||
|
});
|
|||
|
|
|||
|
const actions = initGlobalState(initialState);
|
|||
|
|
|||
|
actions.onGlobalStateChange((newState, prev) => {
|
|||
|
console.log('main change', newState, prev);
|
|||
|
for (const key in newState) {
|
|||
|
initialState[key] = newState[key];
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
// 有key,表示取globalState下的某个子级对象
|
|||
|
// 无key,表示取全部
|
|||
|
|
|||
|
actions.getGlobalState = (key) => {
|
|||
|
return key ? initialState[key] : initialState;
|
|||
|
};
|
|||
|
|
|||
|
export default actions;
|