当前位置:网站首页>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
边栏推荐
猜你喜欢
【深度学习】今日bug(8月2)
Web3 安全风险令人生畏?应该如何应对?
从零开始搭建MySQL主从复制架构
B站回应HR称核心用户是Loser;微博回应宕机原因;Go 1.19 正式发布|极客头条
Why do I strongly recommend using smart async?
SQL中对 datetime 类型操作
[QT] Qt project demo: data is displayed on the ui interface, double-click the mouse to display specific information in a pop-up window
Windows 事件转发到 SQL 数据库
protobuf 反射使用总结
Introduction to spark learning - 1
随机推荐
机器人开发--Universal Scene Description(USD)
罗克韦尔AB PLC RSLogix5000中创建新项目、任务、程序和例程的具体方法和步骤
高薪程序员&面试题精讲系列132之微服务之间如何进行通信?服务熔断是怎么回事?你熟悉Hystrix吗?
MySQL相关介绍
ArkUI如何适配横竖屏
SwinIR实战:详细记录SwinIR的训练过程
SwinIR实战:如何使用SwinIR和预训练模型实现图片的超分
可复现、开放科研、跨学科合作:数据驱动下的科研趋势及应用方案
如何在 DataWorks 中 写SQL语句监控数据的变化到达一定的值 进行提示
Not to be ignored!Features and advantages of outdoor LED display
超分重建数据集
附录A 程序员工作面试的秘密
CopyOnWriteArrayList details
【QT】Qt项目demo:数据在ui界面上显示,鼠标双击可弹窗显示具体信息
20. Valid Parentheses
leetcode-268.丢失的数字
新版本 MaxCompute 的SQL 中支持的 EXTRACT 函数有什么作用?
Introduction to the advantages of the new generation mesh network protocol T-Mesh wireless communication technology
C专家编程 第2章 这不是Bug,而是语言特性 2.3 误做之过
世界顶级级架构师编写2580页DDD领域驱动设计笔记,属实有牌面