React學習筆記六:列表渲染
阿新 • • 發佈:2021-01-22
<!DOCTYPE html>
<html lang=">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>react 學習</title>
<script src="https://cdn.bootcdn.net/ajax/libs/react/16.13.1/umd/react.production.min.js" ></script>
<script src="https://cdn.bootcdn.net/ajax/libs/react-dom/16.13.1/umd/react-dom.production.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/babel-standalone/7.0.0-beta.3/babel.min.js"></script>
</head>
<body>
<div id="app"></div>
<script type="text/babel">
class App extends React.Component {
state = {
list: [{
id: 1,
name: "小米",
height: 133
},
{
id: 2,
name: "小紅" ,
height: 131
},
{
id: 3,
name: "小張",
height: 136
}]
}
render(){
const Lis = this.state.list.map(item=>{
return <li key={item.id}>姓名:{item.name},身高:{item.height}</li>
})
return <ul>
{Lis}
</ul>
}
}
ReactDOM.render(
<App />,
document.getElementById("app")
);
</script>
</body>
</html>