B2C电商
B2B交易系统
智慧门店
分销商城
社区电商
查看更多

提供微商城·微分销·小程序开店需求

5分钟开通你的微信商城店铺!
HiShop > Hi小程序 > 小程序热门 >

小程序点赞收藏功能的实现

2018-09-12 作者:秩名

在微信小程序开发过程中,如果想开发一个点赞收藏功能,需要怎么开发呢,有没有源码,下面为大家解答。

一.收藏

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
        });
       });
    }
  },

推荐文章

微分销 产品资料 领取开店礼包 免费体验
门店管理 裂变获客 商城开发 免费注册