react组件
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <script src="../node_modules/react/umd/react.development.js"></script> <script src="../node_modules/react-dom/umd/react-dom.development.js"></script> <script src="../node_modules/babel-standalone/babel.js"></script> </head> <body> <div id="app"> </div> <script type="text/babel"> let arr = [1,2,3,4]; // 根组件默认拿到全局变量为data的值 在子组件传值直接传值进行调用 class List3 extends React.Component{//必须是大写的首字母 render(){ console.log(this);//符号必须是分号不能是逗号 return( this.props.data.map((item,index)=>{ return ( <div key={index}>{item}</div> ) } ) ) } } function List(arr) { return ( <ul> { arr.map((item,index)=>{ return <li key={index}>{item}</li> }) } </ul> ) } function List2(arr) { return ( <ul> { arr.data.map((item,index)=>{ return <li key={index}>{item}</li> }) } </ul> ) } ReactDOM.render( <div> {List(arr)} <List2 data={arr} /> <List3 data={arr}/> </div>, document.getElementById('app') ) </script> </body> </html>