小工具知识网

当前位置: 首页 > 行业知识 > React-父传子

行业知识

React-父传子

2026-11-12 21:49:43 来源:互联网转载

1.概念

说���:父组件传递数据子组件标签身上绑定属性;子组件接受数据props的参数。props是一个对象,包含父组件传递的所有数据。例如数字、字符串、布尔值、数组、对象、函数、JSX。不允许直接修改父组件传递的数据。

2.例子

// 父传子// 1.父组件传递数据 子组件标签身上绑定属性// 2.子组件接收数据 props的参数function Son(props) {  //props是一个对象,包含父组件传递的所有数据,例如数字、字符串、布尔值、数组、对象、函数、JSX。不允许直接修改父组件传递的数据  return this is son,{props.name};}function App() {  const name = "this is app name";  return (           console.log(123)}        child={this is span2}      >this is span      );}export default App;

3.特殊children

说明:类似与作用域插槽。props.children。 

// 父传子// 1.父组件传递数据 子组件标签身上绑定属性// 2.子组件接收数据 props的参数function Son(props) {  //props是一个对象,包含父组件传递的所有数据,例如数字、字符串、布尔值、数组、对象、函数、JSX。不允许直接修改父组件传递的数据  return this is son,{props.children};}function App() {  const name = "this is app name";  return (           console.log(123)}        child={this is span2}      >this is son 标签里面的内容      );}export default App;

上一篇:服务器gt格式怎么安装?

下一篇:如何使用Flask搭建web程序框架并实现无公网IP远程访问本地程序