站长图库向大家介绍了微信小程序,点赞业务等相关知识,希望对您有所帮助
这篇文章主要为大家详细介绍了微信小程序实现点赞业务,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了微信小程序实现点赞业务的具体代码,供大家参考,具体内容如下:
一、效果

二、实现
一、逻辑
1、从登录界面时,用户数据已经缓存到本地,在onload中从本地获取用户信息保存在data.userInfo中
2、判断用户的_openid是否在loveList返回的列表中,如果是取消赞,如果不是点赞加入昵称到loveList中
3、下面用的是nickName判断,后期优化成使用_openid判断




二、wxml
<!-- wx:index = "index":列表循环后所有位置都可以访问索引 --><view class="item" wx:for="{{list}}" wx:index = "index"> <view class="left"> <image class="avatar"></image> </view> <view class="right"> <view class="nickname">{{item.nickName}}</view> <view class="content">{{item.content}}</view> <view class="image-list"> <image class="image" wx:for="{{item.imageList}}"></image> </view> <view class="time-area"> <view class="time">{{item.time}}</view> <view> <!-- data-index="{{index}}" 1.设置后在回调函数中currentTarget.dataset中显示 --> <image class="operation-button" src="../../images/caozuo.png" catchtap="showOperationPannel" data-index="{{index}}"></image> <!-- 判断当前索引和面盘索引是否一致 --> <view class="operation-pannel" wx:if="{{showOperationPannelIndex == index}}"> <!-- 设置索引和点击函数 --> <view class="tab" catchtap="clickLove" data-index="{{index}}"> <image class="image" src="../../images/love-white.png"></image> <text>赞</text> </view> <view class="tab"> <image class="image" src="../../images/comment-white.png"></image> <text>评论</text> </view> </view> </view> </view> <view class="love-comment"> <!-- item.loveList=重复 item.loveList <view class="love" wx:if="{{item.loveList.length > 0}}"> <image class="love-icon" src="../../images/love-blue.png"></image> <text class="love-nickname" wx:for="{{item.loveList}}">老夫子 兰陵王</text> </view> --> <view class="love" wx:if="{{item.loveList.length > 0}}"> <image class="

