小程序模板网

小程序点赞收藏功能

发布时间:2018-09-12 14:54 所属栏目:小程序开发教程

一.收藏

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


易优小程序(企业版)+灵活api+前后代码开源 码云仓库:starfork
本文地址:https://www.eyoucms.com/wxmini/doc/course/24804.html 复制链接 如需定制请联系易优客服咨询:800182392 点击咨询
QQ在线咨询