开始

评论输入框。和聊天页的输入框是类似的。
image.png

image.png

  1. import userChatBottom from '@/components/user-chat/user-chat-bottom.vue';

复制过来
image.png

image.png

  1. <user-chat-bottom @submit="submit"></user-chat-bottom>
  1. submit(data) {
  2. console.log(data);
  3. }

留言的方法
image.png

image.png

输入留言
image.png
搜索框的组件内设置的高度是120的高度
image.png
加一个view也设置120的高度。占这部分高度,把页面整体高度撑高一点。
image.png

  1. <view style="height: 120upx;"></view>


完全的显示出来了。
image.png

构建评论的数据

image.png

  1. submit(data) {
  2. console.log(data);
  3. let obj = {
  4. id: 1,
  5. fid: 0,
  6. userpic: "../../static/demo/userpic/12.jpg",
  7. username: "小猫咪",
  8. time: time.gettime.gettime(new Date().getTime()),
  9. data: data,
  10. };
  11. this.comment.list.push(obj);
  12. }

image.png

image.png
时间没有转换,再就是 内容不是我们输入的。
image.png

image.png

image.png
需要自己滚动 滚动条到最下面。
image.png

本节代码

  1. <template>
  2. <view>
  3. <detail-info :item="detail"></detail-info>
  4. <view class="u-comment-title">最新评论 {{comment.count}}</view>
  5. <!-- 评论区 start -->
  6. <view class="uni-comment u-comment">
  7. <block v-for="(item,index) in comment.list" :key="index">
  8. <comment-list :item="item" :index="index"></comment-list>
  9. </block>
  10. </view>
  11. <view style="height: 120upx;"></view>
  12. <user-chat-bottom @submit="submit"></user-chat-bottom>
  13. </view>
  14. </template>
  15. <script>
  16. import detailInfo from '@/components/detail/detail-info.vue';
  17. import time from '../../common/time.js';
  18. import commentList from '@/components/detail/comment-list.vue';
  19. import userChatBottom from '@/components/user-chat/user-chat-bottom.vue';
  20. export default {
  21. components: {
  22. detailInfo,
  23. commentList,
  24. userChatBottom
  25. },
  26. data() {
  27. return {
  28. detail: {
  29. userpic: "../../static/demo/userpic/12.jpg",
  30. username: "哈哈",
  31. sex: 0, //0 男 1 女
  32. age: 25,
  33. isguanzhu: false,
  34. title: "我是标题",
  35. titlepic: "../../static/demo/datapic/13.jpg",
  36. morepic: ["../../static/demo/datapic/13.jpg", "../../static/demo/datapic/12.jpg"],
  37. video: false,
  38. share: false,
  39. path: "深圳 龙岗",
  40. sharenum: 20,
  41. commentnum: 30,
  42. goodnum: 20
  43. },
  44. comment: {
  45. count: 20,
  46. list: []
  47. }
  48. }
  49. },
  50. onLoad(e) {
  51. // console.log(e.detailDate);
  52. this.initdata(JSON.parse(e.detailDate));
  53. this.getcomment();
  54. },
  55. // 监听导航右边按钮
  56. onNavigationBarButtonTap(e) {
  57. // console.log(e);
  58. if (e.index == 0) {
  59. console.log("分享");
  60. }
  61. },
  62. methods: {
  63. // 获取评论
  64. getcomment() {
  65. let arr = [
  66. // 一级评论
  67. {
  68. id: 1,
  69. fid: 0,
  70. userpic: "../../static/demo/userpic/12.jpg",
  71. username: "小猫咪",
  72. time: "1555400035",
  73. data: "支持国产,支持DCloud!",
  74. },
  75. // 子级评论
  76. {
  77. id: 2,
  78. fid: 1,
  79. userpic: "../../static/demo/userpic/12.jpg",
  80. username: "小猫咪",
  81. time: "1555400035",
  82. data: "支持国产,支持DCloud!",
  83. },
  84. {
  85. id: 3,
  86. fid: 1,
  87. userpic: "../../static/demo/userpic/12.jpg",
  88. username: "小猫咪",
  89. time: "1555400035",
  90. data: "支持国产,支持DCloud!",
  91. },
  92. {
  93. id: 4,
  94. fid: 0,
  95. userpic: "../../static/demo/userpic/12.jpg",
  96. username: "小猫咪",
  97. time: "1555400035",
  98. data: "支持国产,支持DCloud!",
  99. },
  100. ];
  101. for (let i = 0; i < arr.length; i++) {
  102. arr[i].time = time.gettime.gettime(arr[i].time);
  103. }
  104. this.comment.list = arr;
  105. },
  106. // 初始化数据
  107. initdata(obj) {
  108. console.log('拿到标题:', obj);
  109. uni.setNavigationBarTitle({
  110. title: obj.title
  111. })
  112. },
  113. submit(data) {
  114. console.log(data);
  115. let obj = {
  116. id: 1,
  117. fid: 0,
  118. userpic: "../../static/demo/userpic/12.jpg",
  119. username: "小猫咪",
  120. time: time.gettime.gettime(new Date().getTime()),
  121. data: data,
  122. };
  123. this.comment.list.push(obj);
  124. }
  125. }
  126. }
  127. </script>
  128. <style>
  129. .u-comment-title {
  130. padding: 20upx;
  131. font-size: 30upx;
  132. font-weight: bold;
  133. }
  134. .u-comment {
  135. padding: 0 20upx;
  136. }
  137. </style>

结束