-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprop.html
57 lines (55 loc) · 1.45 KB
/
prop.html
1
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Props</title></head><body><div id="app"></div> <script src="react-15.3.1/build/react.js"></script> <script src="react-15.3.1/build/react-dom.js"></script> <script src="react-15.3.1/browser.js"></script> <script type="text/babel"> var Msg= React.createClass({ render: function(){ var data ="123"; var arr= [1, 2, 3]; return ( <SubMsg str= {data} arr={arr}/> ); } }); var Msg2= React.createClass({ render: function(){ var data ="123"; return ( <SubMsg str= {data} /> ); } }); var SubMsg= React.createClass({ getDefaultProps :function(){ return { arr : [] }; }, render: function(){ var msgArr= []; this.props.arr.forEach(function(elem,index){ msgArr.push(<div key={index}>{elem}</div>) ; }); return( <div>{msgArr}</div> ) } }); ReactDOM.render( <div> <Msg /> <Msg2/> </div>, document.getElementById("app") ) </script></body></html>