当前位置:网站首页>Umijs - data transmission between main and sub applications of Qiankun
Umijs - data transmission between main and sub applications of Qiankun
2022-07-23 15:58:00 【Zong_ 0915】
UmiJs - qiankun Between master and child applications , Data transfer
One . Sending data in the main application
import {
initGlobalState } from 'qiankun';
// Mainly through setGlobalState To put objects into a global common to master and child applications State in .
const {
setGlobalState } = initGlobalState({
});
// Case study
setGlobalState({
userName: window.atob(userName),
age: 10,
});
Two . Receiving data in sub application
import React, {
useState, useEffect } from 'react';
// Need to use useModel To get the data transferred in the main application
import {
useModel } from 'umi';
// Get the parameters passed between master and child applications
const getMainSubProps = () => {
// The name is fixed @@qiankunStateFromMaster
const masterProps = useModel('@@qiankunStateFromMaster');
// You can use one State De storage , In this way, other places only need to introduce this getMainSubProps Components , Get the returned result .
const [ name, setUserName ] = useState<string>([]);
useEffect(() => {
// We need to add ? Of , Prevent null pointer exception
masterProps?.onGlobalStateChange((state: any) => {
const {
userName ,age } = state;
if(userName){
setUserName(userName);
}
});
}, []);
return {
name };
};
export default getMainSubProps;
In sub applications , Just write a basic component , Avoid repeated monitoring . Just listen to the updated value . If you need to use this component on other pages , The pseudocode is as follows :
import getMainSubProps from 'xxx';
const {
age,name} = getMainSubProps();
边栏推荐
猜你喜欢

xml-xxe漏洞之Fake XML cookbook

Can multithreading optimize program performance?

CS5363,CS5350,CS5328几款太阳能板电池充电管理IC的功能特性与参数对比

Chapter 4 event handling of quick mastering QML

《快速掌握QML》第四章 事件处理

备份内容哈哈哈

SCA在得物DevSecOps平台上应用

Unity notes ilruntime access
![[attack and defense world web] difficulty Samsung 9 points introductory question (Part 1): simple_ js、mfw](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[attack and defense world web] difficulty Samsung 9 points introductory question (Part 1): simple_ js、mfw

超详细MP4格式分析
随机推荐
Exclusive interview | open source Summer Star Niu Xuewei
day1
Cookie和Session的区别
Batch deletion with RPM -e --nodeps
C # calculate the number of times a character appears in the string
Camera flashlight modification
Suffix expression (summer vacation daily question 4)
适用于顺序磁盘访问的1分钟法则
MD5 strong collision, secondary decoding,
Redis Key没设置过期时间,为什么被主动删除了
Find the minimum value and location in multiple numbers (with repetition)
Redis sentinel mode
Gear monthly update June
Completely uninstall MySQL in centos7
《快速掌握QML》第四章 事件处理
C语言经典例题-两个分数相加
地图附近名片流量主小程序开发
harbor镜像仓库
redis 主从复制
Php:filter pseudo protocol [bsidescf 2020]had a bad day