所属分类:php教程
收藏功能:
focusFavoriteTab: function (e) {
var that = this;
var isFocus = that.data.isFocus;
console.log("isFocus", isFocus)
var itemId = that.data.itemId;
if (isFocus) {
favoriteService.cancel(that, itemId).then((res) => {
wx.showToast({
title: "取消收藏",
icon: 'success',
duration: 1000
});
this.setData({
isFocus: false,
});
})
} else {
favoriteService.add(that, itemId).then((res) => {
wx.showToast({
title: res.data == 1 ? "收藏成功" : "收藏失败",
icon: 'success',
duration: 1000
});
this.setData({
isFocus: true,
});
});
}
},
登录后复制
点赞功能:
focuslikeTab: function (e) {
var that = this;
var isLike = that.data.isLike;
let itemDetail = this.data.itemDetail
var itemId = that.data.itemId;
if (isLike) {
itemService.cancellike(that, itemId).then((res) => {
wx.showToast({
title: "点赞取消",
icon: 'success',
duration: 1000
});
itemDetail.liked--;
this.setData({
itemDetail:itemDetail
});
this.setData({
isLike: false,
});
})
} else {
itemService.addlike(that, itemId).then((res) => {
wx.showToast({
title: res.data == 1 ? "点赞成功" : "点赞失败",
icon: 'success',
duration: 1000
});
itemDetail.liked++;
this.setData({
itemDetail: itemDetail
});
this.setData({
isLike: true,
});
});
}
},
登录后复制
相关推荐:
关于微信小程序收藏功能的实现
在微信小程序中如何实现点赞功能
以上就是小程序中点赞和收藏功能的实现代码的详细内容,更多请关注zzsucai.com其它相关文章!