import React from "react"
class Hello extends React.Component{
constructor(props){
supre(props)
this.state = {
data:[
{name:"zhangsan",age:18},
{name:"lisi",age:20},
{name:"wangwu",age:21}
]
}
}
/*条件渲染*/
render = ()=>{
let renderHtml = "";
if(this.state.data.length === 0){
renderHtml = (
<div>暂无数据</div>
)
}else{
/*列表渲染*/
renderHtml = (
<ul>
{
this.state.data.map((item,index)=>{
return(<li key={index}>{item.name}:{item.age}</li>)
})
}
</ul>
)
}
}
render(){
return(
<div>
{this.render()}
</div>
)
}
}
暂无评论