Rumah > applet WeChat > Pembangunan program mini > 小程序中点赞和收藏功能的实现代码

小程序中点赞和收藏功能的实现代码

不言
Lepaskan: 2018-09-07 14:47:25
asal
5548 orang telah melayarinya

小程序中的点赞功能和收藏功能是必不可少的,那么该如何实现点赞和收藏两个功能呢?本篇文章将给大家分享小程序中的点赞功能和收藏功能的代码实现。

收藏功能:

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
        });
        this.setData({
          isFocus: false,
        });
      })
    } else {
      favoriteService.add(that, itemId).then((res) => {
        wx.showToast({
          title: res.data == 1 ? "收藏成功" : "收藏失败",
          icon: 'success',
          duration: 1000
        });
        this.setData({
          isFocus: true,
        });
      });
    }
  },
Salin selepas log masuk

点赞功能:

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--;
        this.setData({
          itemDetail:itemDetail
        });
        this.setData({
          isLike: false,
        });
      })
    } else {
      itemService.addlike(that, itemId).then((res) => {
        wx.showToast({
          title: res.data == 1 ? "点赞成功" : "点赞失败",
          icon: 'success',
          duration: 1000
        });
        itemDetail.liked++;
        this.setData({
          itemDetail: itemDetail
        });
        this.setData({
          isLike: true,
        });
      });
    }
  },
Salin selepas log masuk

相关推荐:

关于微信小程序收藏功能的实现

在微信小程序中如何实现点赞功能

Atas ialah kandungan terperinci 小程序中点赞和收藏功能的实现代码. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Artikel terbaru oleh pengarang
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan