关于属性: props 1. 函数: function Title(props){ props.name } 2. 类 class Title extends Component{ render(){ let {name,age} = this.props; return <h3>{name} {age}</h3> } } 组件可以嵌套: --------------------------------------------- --------------------------------------------- 关于props一定注意: 只读,不能修改 --------------------------------------------- <script type="text/babel"> function Title(props){ console.log(props); return <h3>{props.name}</h3> } ReactDOM.render( <div> <Title name="体育标题" age="18" /> </div>, document.querySelector('#root') ) </script> <script type="text/babel"> function Title({name,age}){ return <h3>{name} {age}</h3> } ReactDOM.render( <div> <Title name="体育标题" age="18" /> </div>, document.querySelector('#root') ) </script> <script type="text/babel"> let {Component} = React; class Title extends Component{ render(){ let {name,age} = this.props; return <h3>{name} {age}</h3> } } ReactDOM.render( <div> <Title name="体育标题" age="18" /> <Title name="新闻标题" age="18" /> <Title name="IT标题" age="18" /> </div>, document.querySelector('#root') ) </script> 错误的 关于props一定注意: 只读,不能修改 <script type="text/babel"> let {Component} = React; class Title extends Component{ render(){ this.props.name=456; return <h3>{this.props.name}</h3> } } ReactDOM.render( <Title name={123}/>, document.querySelector('#root') ) </script>