애플릿 좋아요 모음 기능

1827 단어

하나.소장하다

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

2.좋아요를 누르다

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

좋은 웹페이지 즐겨찾기