7.5. 编辑和删除评论

本教程最新版为 2.6,当前版本已放弃维护,请阅读最新版本!

简介

本小节中,我们将在评论中添加编辑和删除的图标,并添加编辑和删除评论的功能。

编辑评论

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 {...

本文章首发在 LearnKu.com 网站上。

为了保证课程的高品质,我们需要对课程进行收费。付费后 才能观看剩余内容。 购买

上一篇 下一篇
讨论数量: 0

暂无话题~