微信小程序实现收藏和取消收藏功能
生活随笔
收集整理的這篇文章主要介紹了
微信小程序实现收藏和取消收藏功能
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
話不多說,直接上代碼
js
data:{isFavorite: false, },//收藏 collect: function(options) {console.log(options)var that = this;var openid = wx.getStorageSync('openid');var isFavorite = this.data.isFavorite;var id = options.currentTarget.dataset.idif (!isFavorite) {var roomId = that.data.roomId;that.setData({isFavorite: true})wx.showToast({title: '收藏成功',icon: 'none'})// 收藏接口wx.request({url: ********",method: 'post',data: {openid: openid,id: this.data.id,},success(res) {that.setData({code:10000})}})}//取消收藏else if (isFavorite) {var roomId = that.data.roomId;that.setData({isFavorite: false})wx.showToast({title: '取消成功',icon: 'none'})// 取消收藏wx.request({url:********",method: 'post',data: {openid: openid,id: this.data.id,},success(res) {if (res.data.code == 1) {that.setData({})}}})}},wxml
<view class="fx"><view class="fx1" bindtap='collect'><image src="{{isFavorite?'/imag/xiangqing_shoucang_cs.png':'/imag/xiangqing_shoucang_hs.png'}}" class="img" id="{{id}}"></image></view><view class="fx2">收藏</view></view>總結(jié)
以上是生活随笔為你收集整理的微信小程序实现收藏和取消收藏功能的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 人生有五不:不等、不管、不看、不做、不给
- 下一篇: Linux中10个有用的命令行补齐命令