登录 主页

React props 的简单使用

2024-06-08 11:02PM

参考:https://www.w3schools.com/react/react_props.asp

Props 是传递给React组件的参数;Props 通过HTML属性传递给组件。

Props 代表属性。

React Props 就像 JavaScript 中的函数参数 属性 在 HTML 中。

要将 props 发送到组件中,请使用与 HTML 属性相同的语法:

eg:

向 Car 元素添加“brand”属性:

const myElement = <Car brand="Ford" />;

该组件接收参数作为 props 目的:

在组件中使用 "brand" 属性: 

function Car(props) {
  return <h2>I am a { props.brand }!</h2>;
} 

返回>>

登录

请登录后再发表评论。

评论列表:

目前还没有人发表评论