7.5. 编辑和删除评论
简介
本小节中,我们将在评论中添加编辑和删除的图标,并添加编辑和删除评论的功能。
编辑评论
1). 添加编辑逻辑
打开 src/store/actions.js
文件,修改 comment
事件(注释部分是涉及的修改):
src/store/actions.js
export const comment = ({ commit, state }, { articleId, comment, commentId }) => {
let articles = state.articles
let comments = []
if (!Array.isArray(articles)) articles = []
for (let article of articles) {
if (parseInt(article.articleId) === parseInt(articleId)) {
comments = Array.isArray(article.comments) ? article.comments : comments
if (comment) {
const { uid = 1, content } = comment
const date = new Date()
if (commentId === undefined) {
const lastComment = comments[comments.length - 1]
if (lastComment) {
commentId = parseInt(lastComment.commentId) + 1
} else {...