comment.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <div class="commentParent">
  3. <div v-for="(item,index) in commentList" :key="index">
  4. <div class="commentItem">
  5. <div class="userImg">
  6. <img v-if="item.userinfo && item.userinfo.user_img" :src="item.userinfo.user_img" alt />
  7. <img v-else src="@/assets/default_img.jpg" alt="">
  8. </div>
  9. <div class="commentContent">
  10. <p>
  11. <span v-if="item.userinfo">{{item.userinfo.name}}</span>
  12. <span v-else>此用户无姓名</span>
  13. <span>{{item.comment_date}}</span>
  14. </p>
  15. <div>
  16. {{item.comment_content}}
  17. <span class="publishs" @click="publishClick(item.comment_id)">回复</span>
  18. </div>
  19. </div>
  20. </div>
  21. <div style="padding-left:8.333vw;"><comment-item @PostPublish="publishClick" :commentChild="item.child"></comment-item></div>
  22. </div>
  23. </div>
  24. </template>
  25. <script>
  26. import commentItem from "./commentItem";
  27. export default {
  28. data() {
  29. return {
  30. commentList:null,
  31. }
  32. },
  33. components: {
  34. commentItem
  35. },
  36. methods: {
  37. async commentData() {
  38. const res = await this.$http.get("/comment/" + this.$route.params.id);
  39. if(res.data){
  40. this.$emit('lengthselect',res.data.length)
  41. }
  42. this.commentList = this.changeCommentData(res.data)
  43. },
  44. changeCommentData(data) {
  45. function fn(temp) {
  46. let arr1 = [];
  47. for (var i = 0; i < data.length; i++) {
  48. if (data[i].parent_id == temp) {
  49. arr1.push(data[i]);
  50. data[i].child = fn(data[i].comment_id);
  51. }
  52. }
  53. return arr1;
  54. }
  55. return fn(null);
  56. },
  57. publishClick(id) {
  58. this.$emit('publishClick',id)
  59. }
  60. },
  61. created() {
  62. this.commentData();
  63. }
  64. };
  65. </script>
  66. <style lang="less">
  67. .commentParent {
  68. padding: 2.778vw 2.778vw;
  69. > div {
  70. border-bottom: 0.278vw solid #e7e7e7;
  71. }
  72. .commentItem {
  73. display: flex;
  74. margin: 2.778vw 0;
  75. .userImg {
  76. margin-right: 2.778vw;
  77. img {
  78. width: 9.722vw;
  79. height: 9.722vw;
  80. }
  81. }
  82. .commentContent {
  83. flex: 1;
  84. position: relative;
  85. p {
  86. font-size: 3.611vw;
  87. color: #555;
  88. display: flex;
  89. justify-content: space-between;
  90. margin-bottom: 1.389vw;
  91. }
  92. div {
  93. font-size: 3.611vw;
  94. }
  95. .publishs{
  96. position: absolute;
  97. right: 0;
  98. color: red;
  99. }
  100. }
  101. }
  102. }
  103. </style>