xiaoxiaoxun

点赞功能(手动更新当前项 无状态刷新页面) ==》点赞的时候手动拼接

                <block wx:if="{{item.tags==0}}">
                  <image class="vote_s" data-num="1" data-id="{{item.id}}" data-index="{{index}}" catchtap="getTagsArticle" src="../../../../images/upvote_s.png"></image>
                  <text style="margin-left:4rpx;">{{item.tags_num}}</text>
                </block>
                <block wx:else>
                  <image class="vote_s" data-num="-1" data-id="{{item.id}}" data-index="{{index}}" catchtap="getTagsArticle" src="../../../../images/vote_s.png"></image>
                  <text style="margin-left:4rpx;">{{item.tags_num}}</text>
                </block>
 
 
 
getTagsArticle(e) {
    console.log(e)
    // 判断是否点赞 1 或者 -1
    let num = e.currentTarget.dataset.num;
    // 当前项的id
    let id = e.currentTarget.dataset.id;
    // 当前项的索引
    let idx = e.currentTarget.dataset.index;
    console.log(num, id, idx)
    const that = this;
    var postsData = {
      id: id,
      num: num
    }
    let dataInfo = requestSign.requestSign(postsData)
    header.sign = dataInfo
    wx.request({
      url: api.get_tagsArticle,
      data: postsData,
      header: header,
      method: \'POST\',
      dataType: \'json\',
      responseType: \'text\',
      success: ({
        data
      }) => {
        console.log(data, \'成功\')
        if (data.code == 1) {
          if (num > 0) { //点赞
            that.data.articleList[idx].tags = 1;
            that.data.articleList[idx].tags_num++;
          } else { //取消点赞
            that.data.articleList[idx].tags = 0;
            that.data.articleList[idx].tags_num--;
          }
          that.setData({
            ["articleList[" + idx + "]"]: that.data.articleList[idx]
          })
        } else {
          wx.showToast({
            title: data.message
          })
        }
      }
    });
  }
发表于 2020-03-06 11:03  z_xun  阅读(290)  评论(0编辑  收藏  举报
 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-02
  • 2022-12-23
  • 2022-12-23
  • 2021-07-25
  • 2021-10-11
  • 2021-01-24
猜你喜欢
  • 2021-06-01
  • 2021-06-25
  • 2021-06-17
  • 2021-12-19
  • 2021-06-01
相关资源
相似解决方案