开始

加一些动画的效果,增加接口跳转到内容页。

优化动画效果

之前引入的动画库
image.png

image.png

  1. <view class="index-list animated rotateIn">

瞬间动画
image.png
旋转进来
image.png
选择低调一点的
image.png
速度快一点。加个fast
image.png

  1. <view class="index-list animated fadeInLeft fast">

关注优化

关注这里,不应该是消失,
image.png

加个感叹号,取反
image.png

  1. <view class="u-f-ac" v-show="!item.isguanzhu">
  2. <view class="icon iconfont icon-zengjia"></view>关注
  3. </view>

需要点击关注。
image.png
增加一个关注事件
image.png

  1. <view class="u-f-ac" v-show="!item.isguanzhu" @tap="guanzhu">

改变值,然后加一个提示
image.png

image.png

image.png

最新版
https://uniapp.dcloud.io/api/ui/prompt.html#showtoast
image.png

image.png

  1. methods:{
  2. guanzhu() {
  3. this.item.isguanzhu = true;
  4. uni.showToast({
  5. title: '关注成功'
  6. });
  7. }
  8. }

image.png

笑脸和哭脸事件

image.png

image.png

  1. <view class="u-f-ac">
  2. <view class="u-f-ac" :class="{'active':(item.infonum.index==1)}"
  3. @tap="caozuo('ding')">
  4. <view class="icon iconfont icon-icon_xiaolian-mian"></view>
  5. {{item.infonum.dingnum}}
  6. </view>
  7. <view class="u-f-ac" :class="{'active':(item.infonum.index==2)}"
  8. @tap="caozuo('cai')">
  9. <view class="icon iconfont icon-kulian"></view>
  10. {{item.infonum.cainum}}
  11. </view>
  12. </view>

image.png
如果点了顶,再点击踩,那么顶就减1,踩加1。
当前点击了顶,又点击一次,那么就什么也不操作。
image.png

image.png

数值一直在累计增加
image.png
最后要修改状态
image.png

  1. caozuo(type) {
  2. switch (type){
  3. case "ding":
  4. if(this.item.infonum.index==1) {return;}
  5. this.item.infonum.dingnum++;
  6. if(this.item.infonum.index==2) {
  7. this.item.infonum.cainum--;
  8. }
  9. this.item.infonum.index=1;
  10. break;
  11. case "cai":
  12. if(this.item.infonum.index==2) {return;}
  13. this.item.infonum.cainum++;
  14. if(this.item.infonum.index==2) {
  15. this.item.infonum.dingnum--;
  16. }
  17. this.item.infonum.index=2;
  18. break;
  19. default:
  20. break;
  21. }
  22. }

顶过之后不能再顶了。
image.png
点击踩之后,前面的顶减去1
image.png

跳转内容详情页

title和图片增加点击事件
image.png

  1. <view class="index-list2" @tap="oepndetail()">{{item.title}}</view>
  2. <view class="index-list3 u-f-ajc" @tap="oepndetail()">

image.png

  1. oepndetail() {
  2. console.log('进入详情页');
  3. }

点击标题
image.png

最终代码

  1. <template>
  2. <view class="index-list animated fadeInLeft fast">
  3. <view class="index-list1 u-f-ac u-f-jsb">
  4. <view class="u-f-ac">
  5. <image :src="item.userpic" mode="widthFix" lazy-load></image>
  6. {{item.username}}
  7. </view>
  8. <view class="u-f-ac" v-show="!item.isguanzhu" @tap="guanzhu">
  9. <view class="icon iconfont icon-zengjia"></view>关注
  10. </view>
  11. </view>
  12. <view class="index-list2" @tap="oepndetail()">{{item.title}}</view>
  13. <view class="index-list3 u-f-ajc" @tap="oepndetail()">
  14. <!-- 图片 -->
  15. <image :src="item.titlepic" mode="widthFix" lazy-load>
  16. </image>
  17. <!-- 视频 -->
  18. <template v-if="item.type=='video'">
  19. <view class="index-list-play icon iconfont icon-bofang"></view>
  20. <view class="index-list-playinfo">
  21. {{item.playnum}}播放 {{item.long}}
  22. </view>
  23. </template>
  24. </view>
  25. <view class="index-list4 u-f-ac u-f-jsb">
  26. <view class="u-f-ac">
  27. <view class="u-f-ac" :class="{'active':(item.infonum.index==1)}"
  28. @tap="caozuo('ding')">
  29. <view class="icon iconfont icon-icon_xiaolian-mian"></view>
  30. {{item.infonum.dingnum}}
  31. </view>
  32. <view class="u-f-ac" :class="{'active':(item.infonum.index==2)}"
  33. @tap="caozuo('cai')">
  34. <view class="icon iconfont icon-kulian"></view>
  35. {{item.infonum.cainum}}
  36. </view>
  37. </view>
  38. <view class="u-f-ac">
  39. <view class="u-f-ac">
  40. <view class="icon iconfont icon-pinglun1"></view>
  41. {{item.commentnum}}
  42. </view>
  43. <view class="u-f-ac">
  44. <view class="icon iconfont icon-zhuanfa"></view>
  45. {{item.sharenum}}
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. export default {
  53. props: {
  54. item: Object,
  55. index: Number
  56. },
  57. onLoad(){
  58. console.log('子组件内',this.item);
  59. },
  60. methods:{
  61. guanzhu() {
  62. this.item.isguanzhu = true;
  63. uni.showToast({
  64. title: '关注成功'
  65. });
  66. },
  67. caozuo(type) {
  68. switch (type){
  69. case "ding":
  70. if(this.item.infonum.index==1) {return;}
  71. this.item.infonum.dingnum++;
  72. if(this.item.infonum.index==2) {
  73. this.item.infonum.cainum--;
  74. }
  75. this.item.infonum.index=1;
  76. break;
  77. case "cai":
  78. if(this.item.infonum.index==2) {return;}
  79. this.item.infonum.cainum++;
  80. if(this.item.infonum.index==2) {
  81. this.item.infonum.dingnum--;
  82. }
  83. this.item.infonum.index=2;
  84. break;
  85. default:
  86. break;
  87. }
  88. },
  89. oepndetail() {
  90. console.log('进入详情页');
  91. }
  92. }
  93. }
  94. </script>
  95. <style scoped>
  96. .index-list {
  97. padding: 20upx;
  98. border-bottom: 1upx solid #EEEEEE;
  99. }
  100. .index-list1 {
  101. /* display: flex; */
  102. /* justify-content: space-between; */
  103. /* align-items: center; */
  104. }
  105. .index-list1>view:first-child {
  106. /* display: flex;
  107. align-items: center; */
  108. color: #999999;
  109. }
  110. .index-list1>view:first-child image {
  111. width: 95upx;
  112. height: 90upx;
  113. border-radius: 100%;
  114. margin-right: 10upx;
  115. }
  116. .index-list1>view:last-child {
  117. /* display: flex;
  118. align-items: center; */
  119. background: #F4F4F4;
  120. border-radius: 5upx;
  121. padding: 0 10upx;
  122. }
  123. .index-list2 {
  124. padding-top: 15upx;
  125. font-size: 32upx;
  126. }
  127. .index-list3 {
  128. position: relative;
  129. padding-top: 15upx;
  130. }
  131. .index-list3>image {
  132. width: 100%;
  133. border-radius: 20upx;
  134. }
  135. .index-list-play {
  136. position: absolute;
  137. font-size: 140upx;
  138. color: #FFFFFF;
  139. }
  140. .index-list-playinfo {
  141. position: absolute;
  142. background: rgba(51, 51, 51, 0.72);
  143. color: #FFFFFF;
  144. bottom: 8upx;
  145. right: 8upx;
  146. border-radius: 40upx;
  147. font-size: 22upx;
  148. padding: 0 12upx;
  149. }
  150. .index-list4 {
  151. padding: 15upx 0;
  152. /* display: flex; */
  153. /* justify-content: space-between; */
  154. /* align-items: center; */
  155. }
  156. .index-list4 view {
  157. color: #999999;
  158. }
  159. .index-list4>view:first-child {
  160. /* display: flex;
  161. align-items: center; */
  162. }
  163. .index-list4>view:last-child {
  164. /* display: flex;
  165. align-items: center; */
  166. }
  167. .index-list4>view>view {
  168. /* display: flex;
  169. align-items: center; */
  170. }
  171. .index-list4>view>view>view,
  172. .index-list4>view>view:first-child {
  173. margin-right: 10upx;
  174. }
  175. .index-list4 .active,.index-list4 .active>view{
  176. color: #c5f61c;
  177. }
  178. </style>

结束