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


                    <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
              })
            }
          }
        });
      }
  • 相关阅读:
    k8s之Controller Manager(七)
    k8s 之apiserver部署(六)
    k8s之etcd集群安装(五)
    k8s 之harbor仓库安装(四)
    k8s 之docker环境部署 (三)
    如何在PPT中同时插入多张图片且每张占一页
    ICMPV6
    整理桌面 | Windows自带工具
    教你在Linux中如何配置网络地址
    解决在gns3中wireshark抓包无法显示和实时刷新问题
  • 原文地址:https://www.cnblogs.com/xiaoxiaoxun/p/12425419.html
Copyright © 2020-2023  润新知