当前位置:网站首页>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
边栏推荐
猜你喜欢

正向代理与反向代理

MySQL窗口函数

自动化部署+整合SSM项目

机器人开发--Universal Scene Description(USD)

Interpretation of the 2021 Cost of Data Breach Report

不可忽略!户外LED显示屏的特点及优势

使用.NET简单实现一个Redis的高性能克隆版(一)

Small Tools (4) integrated Seata1.5.2 distributed transactions

To add digital wings to education, NetEase Yunxin released the overall solution of "Internet + Education"

MATLAB | 一种简易的随机曼陀罗图形生成函数
随机推荐
Kubernetes 笔记 / 入门 / 生产环境 / 用部署工具安装 Kubernetes / 用 kubeadm 启动集群 / 安装 kubeadm
常见分布式理论(CAP、BASE)和一致性协议(Gosssip、Raft)
protobuf 中数据编码规则
C专家编程 第3章 分析C语言的声明 3.7 typedef struct foo{... foo;}的含义
MPLS的wpn实验
Difference and performance comparison between HAL and LL library of STM32
实时渲染流程操作复杂吗,如何实现?
20. Valid Parentheses
Cookie和Session的关系
C专家编程 第1章 C:穿越时空的迷雾 1.7 编译限制
ArkUI如何适配横竖屏
Auto Scaling 弹性伸缩(运维释放人力)
C专家编程 第1章 C:穿越时空的迷雾 1.6 它很棒,但它符合标准吗
QT QT 】 【 to have developed a good program for packaging into a dynamic library
Selective Search学习笔记
How to start an NFT collection
Yuan xiaolin: Volvo focus on travel security, and put it perfectly
C专家编程 第3章 分析C语言的声明 3.5 typedef可以成为你的朋友
Small Tools (4) integrated Seata1.5.2 distributed transactions
面试不再被吊打!这才是Redis分布式锁的七种方案的正确打开方式