1、问题背景
2、实现源码
<!DOCTYPE html> <html> <head> <Meta charset="UTF-8"> <title>React生成组件类</title> <script type="text/javascript" src="../js/react.js" ></script> <script type="text/javascript" src="../js/react-dom.js" ></script> <script type="text/javascript" src="../js/browser.min.js" ></script> <script type="text/babel"> var Person = React.createClass({ render:function(){ return <h3>姓名:{this.props.username},年龄:{this.props.age}</h3> } }); ReactDOM.render( <Person username="胡立新" age="23"/>,document.getElementById("per") ); </script> </head> <body> <div id="per"></div> </body> </html>
3、实现结果