实现功能
1、渲染评论列表
2、删除评论
3、渲染导航栏和高亮
4、评论列表排序功能
5、获取评论
6、点击发布按钮发布评论
7、清空输入框
8、重新聚焦
实现代码
1、需要引入
import React, {
useRef, useState } from 'react'
import avatar from "../logo.png" //头像
import "./css/index.css" //样式
2、样式----[./css/index.css]
* {
margin: 0;
padding: 0;
}
.comment-box {
width: 1000px;
margin: 20px auto;
height: 200px;
}
/* 导航栏 */
.comment-tabs {
display: flex;
align-items: end;
font-weight: normal;
margin-bottom: 20px;
}
.tabs-left {
margin-right: 20px;
font-size: 14px;
}
.tabs-left p span {
margin-left: 6px;
color: #666;
font-size: 10px;
}
.tabs-right {
display: flex;
color: #666;
font-size: 10px;
}
.tabs-right .active {
color: #08a17d;
font-weight: 500;
}
.tabs-right div span {
display: inline-block;
margin: 0 6px;
height: 6px;
border-left: 1px solid #666;
}
.tabs-right div:last-child span {
border: none;
}
/* 发表评论 */
.comment-send {
display: flex;
align-items: center;
justify-content: space-between;
height: 40px;
}
.avatar {
width: 35px;
height: 35px;
margin-left: 10px;
overflow: hidden;
border-radius: 35px;
border: 1px solid #08a17d;
}
.avatar img {
width: 100%;
height: 100%;
}
.comment-