2018-10-22 21:20:28 +08:00
---
order: 0
title:
zh-CN: 基本评论
en-US: Basic comment
---
## zh-CN
2018-10-28 22:09:38 +08:00
一个基本的评论组件,带有作者、头像、时间和操作。
2018-10-22 21:20:28 +08:00
## en-US
A basic comment with author, avatar, time and actions.
````jsx
import { Comment, Icon, Tooltip, Avatar } from 'antd';
import moment from 'moment';
class App extends React.Component {
state = {
likes: 0,
dislikes: 0,
action: null,
}
like = () => {
this.setState({
likes: 1,
dislikes: 0,
action: 'liked',
});
}
dislike = () => {
this.setState({
likes: 0,
dislikes: 1,
action: 'disliked',
})
}
render() {
const { likes, dislikes, action } = this.state;
const actions = [
< span >
< Tooltip title = "Like" >
< Icon
type="like"
2018-10-29 22:05:42 +08:00
theme={action === 'liked' ? 'filled' : 'outlined'}
2018-10-22 21:20:28 +08:00
onClick={this.like}
/>
< / Tooltip >
< span style = {{ paddingLeft: 8 , cursor: ' auto ' } } >
{likes}
< / span >
< / span > ,
< span >
< Tooltip title = "Dislike" >
< Icon
type="dislike"
2018-10-29 22:05:42 +08:00
theme={action === 'disliked' ? 'filled' : 'outlined'}
2018-10-22 21:20:28 +08:00
onClick={this.dislike}
/>
< / Tooltip >
< span style = {{ paddingLeft: 8 , cursor: ' auto ' } } >
{dislikes}
< / span >
< / span > ,
< span > Reply to< / span > ,
];
return (
< Comment
2018-10-29 00:26:13 +08:00
actions={actions}
2018-10-22 21:20:28 +08:00
author={< a > Han Solo< / a > }
avatar={
< Avatar
src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png"
alt="Han Solo"
/>
}
2018-10-29 00:26:13 +08:00
content={
2018-10-30 19:25:54 +08:00
< p > We supply a series of design principles, practical patterns and high quality design resources (Sketch and Axure), to help people create their product prototypes beautifully and efficiently.< / p >
2018-10-29 00:26:13 +08:00
}
2018-10-30 00:17:26 +08:00
datetime={
2018-10-29 22:05:42 +08:00
< Tooltip title = {moment().format('YYYY-MM-DD HH:mm:ss ' ) } >
< span > {moment().fromNow()}< / span >
< / Tooltip >
}
2018-10-29 00:26:13 +08:00
/>
2018-10-22 21:20:28 +08:00
);
}
}
ReactDOM.render(< App / > , mountNode);
````