一、主应用
在主应用加粗样式的组件内或者main.ts中
import { initGlobalState } from 'qiankun';
const { setGlobalState, } = initGlobalState({});
setGlobalState({
userName: '张三',
age: 10,
});
二、子应用
在子应用的任意组件中
import { singleSpaPropsSubject } from '../single-spa/single-spa-props';
ngOnInit() {
singleSpaPropsSubject.subscribe(props=>{
// @ts-ignore
props.onGlobalStateChange(state=>{
console.log('state',state)
},true)
})
}
//写true是立即监听,如果不写true,就拿不到首次传过来的值