Component({ options: { styleIsolation: "apply-shared" }, properties: { item: Object }, data: { like: 1, likeEnable: true }, methods: { getPublisherInfo: function () { wx.navigateTo({ url: "/pages/publisher/publisher?id=" + this.properties.item.id }) }, toggleLike: function () { if (!this.data.likeEnable) return this.setData({ likeEnable: false }) const db = wx.cloud.database() if (this.data.like == 0) { db.collection("likeData").add({ data: { type: "publisher", id: this.properties.item.id }, success: function() { this.setData({ like: 1, likeEnable: true }) wx.showToast({ title: "已收藏", }) }.bind(this), fail: function() { wx.showToast({ title: "网络错误", icon: "none" }) } }) } else { db.collection("likeData").where({ type: "publisher", id: this.properties.item.id }).remove({ success: function() { this.setData({ like: 0, likeEnable: true }) wx.showToast({ title: "已取消收藏", }) }.bind(this), fail: function() { wx.showToast({ title: "网络错误", icon: "none" }) } }) } } } })