评论列表案例
需求分析
步骤一渲染评论列表
import React from 'react';
import ReactDOM, { render } from 'react-dom';
class App extends React.Component{
//初始化状态
state = {
comments:[
{id:1,name:'jack',content:'沙发'},
{id:2,name:'rose',content:'板凳'},
{id:3,name:'mama',content:'楼主好人'}
]
}
render(){
return(
<div className='app'>
<div>
<input type='text' className='user' placeholder='请输入评论人'></input>
<br></br>
<textarear className='content'
cols ='30'
rows = '10'
placeholder='请输入评论内容'
/> <br></br>
<button>发表评论</button>
</div>
<div className='no-content'>暂无评论</div>
<ul>
{this.state.comments.map(item=>(
<li key={item.id}>
<h3>{item.name}</h3>
<p>{item.content}</p>
</li>