react—props属性

 props属性:将组件外部的数据=>组件内部

任务:将组件外部的数据=>组件内部,渲染出来

 1 <script type="text/babel">
 2   class MyComponent extends React.Component{
 3     render(){
 4       console.log(this.props);
 5       const {name,sex,age} = this.props;
 6       return (
 7         <div>
 8           <h1>姓名:{name}</h1>
 9           <h1>性别:{sex}</h1>
10           <h1>年龄:{age}</h1>
11         </div>
12       )
13     }
14   }
15   let person = {
16     name:"孙尚香",
17     sex:"",
18     age:"15",
19   }
20   ReactDOM.render(<MyComponent {...person}/>,document.getElementById("root"))
21 </script>

猜你喜欢

转载自www.cnblogs.com/minyDong/p/12466105.html
今日推荐