小程序點贊收藏功能的實現(xiàn)
2018-09-12
導讀:在微信小程序開發(fā)過程中,如果想開發(fā)一個點贊收藏功能,需要怎么開發(fā)呢,有沒有源碼,下面為大家解答。...
在微信小程序開發(fā)過程中,如果想開發(fā)一個點贊收藏功能,需要怎么開發(fā)呢,有沒有源碼,下面為大家解答。
一.收藏
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 }); that.setData({ isFocus: false, }); }) } else { favoriteService.add(that, itemId).then((res) => { wx.showToast({ title: res.data == 1 ? "收藏成功" : "收藏失敗", icon: 'success', duration: 1000 }); that.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--; that.setData({ itemDetail:itemDetail, isLike: false }); }) } else { itemService.addlike(that, itemId).then((res) => { wx.showToast({ title: res.data == 1 ? "點贊成功" : "點贊失敗", icon: 'success', duration: 1000 }); itemDetail.liked++; that.setData({ itemDetail: itemDetail, isLike: true }); }); } },
第二部分:如何開通一個小商店
您可能感興趣: 小程序開發(fā)