当前位置:网站首页>Component communication - parent-child component communication
Component communication - parent-child component communication
2022-08-03 16:38:00 【Is a small fish balls duck】
Before learning component communication, we need to first understand what is a component and what is the meaning of component communication?
1. What is a component?
A component is a piece of html code that can be reused. The component reuses the structure of HTML and the style of css
2. What is the significance of component communication?
Make the component structure or data more flexible and get a higher reuse effect
3. What standards do components need to meet for communication?
The one-way data flow is the communication method that satisfies the father-to-child transmission
4. Parent-to-child component communication process?
- Copy the html code that needs to be split in the parent component to the child component, import the component into the parent component, and mount it directly
- Bind a custom property to the child component tag in the parent component and pass data to the child component
- The props in the child component to receive the data passed by the parent component, the class component: this.props, the function component: props
As shown in the figure above, in order to save code, use the least code and practice the most complete functions, so we use split components, split the same structure into a sub-component, and then pass the parent-childway to pass data
Code demo
Parent component
export default class App extends Component {constructor(){super()this.state={list1:['gentle','kind','beautiful'],list2:['12k-15k','15k-20k','20k-25k']}}render() {let {list1,list2}=this.statereturn (
)}}
Introduce a child component into the parent component, bind a list property to the child component, and pass data to the child component
Subcomponents
export default function List(props) {let {list}=propsreturn ({list.map((item,index)=>{return (- {item}
)})}
)}
In child components, we use function components to directly call the props method to receive the passed data
边栏推荐
- C专家编程 第1章 C:穿越时空的迷雾 1.7 编译限制
- mysql delete execution error: You can't specify target table 'doctor_info' for update in FROM clause
- 83. Remove Duplicates from Sorted List
- 如何设计大电流九线导电滑环
- C专家编程 第3章 分析C语言的声明 3.2 声明是如何形成的
- C专家编程 第3章 分析C语言的声明 3.5 typedef可以成为你的朋友
- MySQL窗口函数 PARTITION BY()函数介绍
- Why do I strongly recommend using smart async?
- 元宇宙系列--Value creation in the metaverse
- 视频人脸识别和图片人脸识别的关系
猜你喜欢
How much do you know about the intelligent operation and maintenance service of data warehouse based on DMS?
Auto Scaling 弹性伸缩(运维释放人力)
世界顶级级架构师编写2580页DDD领域驱动设计笔记,属实有牌面
To participate in sweepstakes, incoming new programmers magazine welfare!
建造者模式/生成器模式
设置海思芯片MMZ内存、OS内存详解
B站回应HR称核心用户是Loser;微博回应宕机原因;Go 1.19 正式发布|极客头条
Difference and performance comparison between HAL and LL library of STM32
如何选择合适的导电滑环型号
MATLAB | 一种简易的随机曼陀罗图形生成函数
随机推荐
世界顶级级架构师编写2580页DDD领域驱动设计笔记,属实有牌面
请问下这个hologres维表是被缓存了么?怎么直接Finished了
Tolstoy: There are only two misfortunes in life
C专家编程 第3章 分析C语言的声明 3.6 typedef int x[10]和#define x int[10]的区别
测试测试测试
面试不再被吊打!这才是Redis分布式锁的七种方案的正确打开方式
Hannah荣获第六季完美童模全球总决赛全球人气总冠军
如何在 DataWorks 中 写SQL语句监控数据的变化到达一定的值 进行提示
最强分布式锁工具:Redisson
【QT】Qt 给已经开发好的程序快速封装成动态库
高效的组织信息共享知识库是一种宝贵的资源
SwinIR实战:如何使用SwinIR和预训练模型实现图片的超分
AI+BI+Visualization, Deep Analysis of Sugar BI Architecture
Spark entry learning-2
生产环境如何删除表呢?只能在SQL脚本里执行 drop table 吗
How much do you know about the intelligent operation and maintenance service of data warehouse based on DMS?
EA 改口,称单人游戏是产品组合中“非常重要的一部分”
protobuf 中数据编码规则
MySQL查询语法
设置海思芯片MMZ内存、OS内存详解