首页 > 其他分享 >评论内容组件

评论内容组件

时间:2022-10-17 10:45:58浏览次数:44  
标签:comment color height 内容 组件 评论 font 30px size

基本样式 :

<template>
  <van-cell class="comment-item">
    <van-image
      slot="icon"
      class="avatar"
      round
      fit="cover"
      src="https://img.yzcdn.cn/vant/cat.jpeg"
    />
    <div slot="title" class="title-wrap">
      <div class="user-name">用户名称</div>
      <van-button
        class="like-btn"
        icon="good-job-o"
      >赞</van-button>
    </div>

    <div slot="label">
      <p class="comment-content">这是评论内容</p>
      <div class="bottom-info">
        <span class="comment-pubdate">4天前</span>
        <van-button
          class="reply-btn"
          round
        >回复 0</van-button>
      </div>
    </div>
  </van-cell>
</template>

<script>
export default {
  name: 'CommentItem',
  props: {
    //每行的评论信息  
    comment: {
      type: Object,
      required: true
    }
  },
  methods: {}
}
</script>

<style scoped lang="less">
.comment-item {
  .avatar {
    width: 72px;
    height: 72px;
    margin-right: 25px;
  }
  .title-wrap {
    display: flex;
    justify-content: space-between;
    align-items: center;
    .user-name {
      color: #406599;
      font-size: 26px;
    }
  }
  .comment-content {
    font-size: 32px;
    color: #222222;
    word-break: break-all;
    text-align: justify;
  }
  .comment-pubdate {
    font-size: 19px;
    color: #222;
    margin-right: 25px;
  }
  .bottom-info {
    display: flex;
    align-items: center;
  }
  .reply-btn {
    width: 135px;
    height: 48px;
    line-height: 48px;
    font-size: 21px;
    color: #222;
  }
  .like-btn {
    height: 30px;
    padding: 0;
    border: none;
    font-size: 19px;
    line-height: 30px;
    margin-right: 7px;
    .van-icon {
      font-size: 30px;
    }   
  }
  .liked{
      background-color:orange;   
   }
}
</style>

添加动态评论,从评论组件list  ====》 单个评论组件item ,传值 item 是每个评论的信息 comment ;

and :封装 2  个接口,给评论点赞和取消点赞的接口 ;

<template>
  <van-cell class="comment-item">
    <!-- 评论的头像 -->
    <van-image
      slot="icon"
      class="avatar"
      round
      fit="cover"
      :src="comment.aut_photo"
    />
    <div slot="title" class="title-wrap">
      <!-- 作者名字 -->
      <div class="user-name">{{ comment.aut_name }}</div>
      <!-- 点赞的处理逻辑 -->
      <van-button
        class="like-btn"
        :icon="comment.is_liking ? 'good-job' : 'good-job-o'"
        >{{ comment.is_liking ? "已赞" : "赞" }}</van-button
      >
    </div>

    <div slot="label">
      <!-- 评论的具体内容 -->
      <p class="comment-content">{{ comment.content }}</p>
      <div class="bottom-info">
        <!-- 评论的时间 -->
        <span class="comment-pubdate">{{ comment.pubdate | formatTime }}</span>
        <!-- 回复评论个数 -->
        <van-button class="reply-btn" round
          >回复 {{ comment.reply_count }}</van-button
        >
      </div>
    </div>
  </van-cell>
</template>

<script>
import { addCommentLikeApi, delCommentLikeApi } from "@/api/Article";
export default {
  name: "CommentItem",
  props: {
    //每行的评论信息
    comment: {
      type: Object,
      required: true,
    },
  },
  methods: {},
};
</script>

<style scoped lang="less">
.comment-item {
  .avatar {
    width: 72px;
    height: 72px;
    margin-right: 25px;
  }
  .title-wrap {
    display: flex;
    justify-content: space-between;
    align-items: center;
    .user-name {
      color: #406599;
      font-size: 26px;
    }
  }
  .comment-content {
    font-size: 32px;
    color: #222222;
    word-break: break-all;
    text-align: justify;
  }
  .comment-pubdate {
    font-size: 19px;
    color: #222;
    margin-right: 25px;
  }
  .bottom-info {
    display: flex;
    align-items: center;
  }
  .reply-btn {
    width: 135px;
    height: 48px;
    line-height: 48px;
    font-size: 21px;
    color: #222;
  }
  .like-btn {
    height: 30px;
    padding: 0;
    border: none;
    font-size: 19px;
    line-height: 30px;
    margin-right: 7px;
    .van-icon {
      font-size: 30px;
    }
  }
  .liked {
    background-color: orange;
  }
}
</style>

ps:视图更新,就是发送接口

调用接口点赞 和 取消点赞 :

<template>
  <van-cell class="comment-item">
    <!-- 评论的头像 -->
    <van-image
      slot="icon"
      class="avatar"
      round
      fit="cover"
      :src="comment.aut_photo"
    />
    <div slot="title" class="title-wrap">
      <!-- 作者名字 -->
      <div class="user-name">{{ comment.aut_name }}</div>
      <!-- 点赞的处理逻辑 -->
      <van-button
        @click="clickHandler"
        :loading="isLoading"
        class="like-btn"
        :icon="comment.is_liking ? 'good-job' : 'good-job-o'"
        >{{ comment.is_liking ? "已赞" : "赞"
        }}{{ comment.like_count }}</van-button
      >
    </div>

    <div slot="label">
      <!-- 评论的具体内容 -->
      <p class="comment-content">{{ comment.content }}</p>
      <div class="bottom-info">
        <!-- 评论的时间 -->
        <span class="comment-pubdate">{{ comment.pubdate | formatTime }}</span>
        <!-- 回复评论个数 -->
        <van-button class="reply-btn" round
          >回复 {{ comment.reply_count }}</van-button
        >
      </div>
    </div>
  </van-cell>
</template>

<script>
import { addCommentLikeApi, delCommentLikeApi } from "@/api/Article";
export default {
  name: "CommentItem",
  props: {
    //每行的评论信息
    comment: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      isLoading: false, // 节流阀
    };
  },
  methods: {
    async clickHandler() {
      // 判断是否登录,未登录不能点赞
      // 开始转圈圈,按钮不能点击了
      this.isLoading = true;
      if (!this.$store.state.user) return this.$toast.fail("登录才可以操作");
      try {
        if (this.comment.is_liking) {
          // 已点赞,取消点赞
          await delCommentLikeApi(this.comment.com_id);
          this.comment.like_count--;
        } else {
          // 未点赞就点赞
          await addCommentLikeApi({
            target: this.comment.com_id,
          });
          this.comment.like_count++;
        }
        // 视图更新(点赞按钮的颜色变化) 取反即可
        this.comment.is_liking = !this.comment.is_liking;
      } catch (error) {
        console.log(error);
      }
      // 结束转圈圈,按钮可以点击了
      this.isLoading = false;
    },
  },
};
</script>

<style scoped lang="less">
.comment-item {
  .avatar {
    width: 72px;
    height: 72px;
    margin-right: 25px;
  }
  .title-wrap {
    display: flex;
    justify-content: space-between;
    align-items: center;
    .user-name {
      color: #406599;
      font-size: 26px;
    }
  }
  .comment-content {
    font-size: 32px;
    color: #222222;
    word-break: break-all;
    text-align: justify;
  }
  .comment-pubdate {
    font-size: 19px;
    color: #222;
    margin-right: 25px;
  }
  .bottom-info {
    display: flex;
    align-items: center;
  }
  .reply-btn {
    width: 135px;
    height: 48px;
    line-height: 48px;
    font-size: 21px;
    color: #222;
  }
  .like-btn {
    height: 30px;
    padding: 0;
    border: none;
    font-size: 19px;
    line-height: 30px;
    margin-right: 7px;
    .van-icon {
      font-size: 30px;
    }
  }
  .liked {
    background-color: orange;
  }
}
</style>

标签:comment,color,height,内容,组件,评论,font,30px,size
From: https://www.cnblogs.com/zhulongxu/p/16798347.html

相关文章

  • Input 组件的绑定值改变,但是页面不跟随改变
    Input为受控组件,它总会显示Vue绑定值。通常情况下,应当处理input事件,并更新组件的绑定值(或使用v-model)。否则,输入框内显示的值将不会改变。不支持v-model修饰符。......
  • [Vue]子组件与父组件之间传值
    1.父组件与子组件传值props1.1定义父组件,父组件传递 inputText这个数值给子组件://父组件//引入的add-widget组件//使用v-bind的缩写语法通常更简单:<add-widget:m......
  • 本周内容总结
    文件操作文件的概念就是操作系统暴露给用户操作硬盘的快捷方式双击一个文件其实是从硬盘将数据加载到内存ctrl+s保存文件其实是将内存中的数据刷到硬盘保存......
  • git查看某次提交/更新所更改的文件及内容
    参考:(96条消息)git查看某次提交/更新所更改的文件及内容_hyupeng1006的博客-CSDN博客_git查看提交的文件eg.gitshow548c72f42f51c22dbf2fdf133426e094c59789e4--st......
  • 使用阿里的中国地图的json替换echarts中的china.js中的内容
    使用阿里的中国地图的json替换echarts中的china.js中的内容文末有相关资源这两天公司要求做一个地图展示要求每个省份根据用户量多少展示不同的颜色,且给每个市级单位加......
  • Vue组件和插件
    两者的区别组件注册通过“Vue.component”或“components”属性,而插件通过“Vue.use()”;组件是用来构成App的业务模块,它的目标是“App.vue”,而插件是用来增强技术栈的功......
  • 内容回顾
    本周内容总结回顾:1.文件相关内容1.文件操作文件其实就是操作系统给我们一个快捷操作硬盘的方式,我们双击打开一个文本文件就是相当于硬盘存储的数据,加载到内存中2.文件......
  • SpringCloud的Eureka组件
    SpringCloud的Eureka组件1.*Eureka概述1.*.&Eureka是什么Eureka是Netflix的一个子模块,也是核心模块之一。Eureka是一个基于REST的服务,用于定位服务,以实现云端中间层......
  • springBoot 快速开发 即相关内容
    在Boot中我们要是不想使用tomcat服务器想使用jetty的服务器的话修改一下pom.xml就行了  修改服务器端口(在配置文件中我们直接输入port就可以修改但是注!我......
  • 文章的评论 和 评论的恢复组件
    封装请求接口:get提交的query数据放在params里面(或者放在url?后面)/***文章评论*功能1:获取文章的评论*======》typea评论类型,a-对文章(article)的评......