wxml代码如下:
<image src="{{isFavorite=='false'?'/images/menu/collect.png':'/images/menu/uncollect.png'}}" class='collect' bindtap='collect'></image><span class="num font_s30 font_c32">收藏</span>
js部分代码如下:
data: {
isFavorite: "false",
},
collect:function() {
var that = this;
var isFavorite = that.data.isFavorite;
//收藏
if (isFavorite == 'false') {
var roomId = that.data.roomId;
that.setData({
isFavorite:'true'
})
wx.showToast({
title: '收藏成功',
icon: 'none'
})
}
//取消收藏
else if(isFavorite == 'true') {
var roomId = that.data.roomId;
that.setData({
isFavorite: 'false'
})
wx.showToast({
title: '取消成功',
icon: 'none'
})
}
},
实现效果如下:
这里都是前端代码,我只负责写页面和调接口,至于后端代码怎么写的,我也不清楚