小程序模板網(wǎng)

小程序點贊收藏功能

發(fā)布時間:2018-09-12 14:54 所屬欄目:小程序開發(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
        });
       });
    }
  },


易優(yōu)小程序(企業(yè)版)+靈活api+前后代碼開源 碼云倉庫:starfork
本文地址:http://22321a.com/wxmini/doc/course/24804.html 復(fù)制鏈接 如需定制請聯(lián)系易優(yōu)客服咨詢:800182392 點擊咨詢
QQ在線咨詢