交互反饋就是在用戶出發某事件之后,給用戶一個反饋信息,這要是一個很友好的習慣。
在小程序中是通過一下幾種方式實現的:
1.wx.showToast()方法
showToast: function (postscollected, postcollected) { wx.setStorageSync("posts_collected", postscollected); //跟新數據綁定變量,從而且還圖片 this.setData({ collected: postcollected }) //這里調用了wx.showToast()方法 wx.showToast({ title: postcollected?"收藏成功":"取消收藏", duration:2000, icon:"success", }) },
實現效果如圖:
再次點擊收藏按鈕:
2.wx.showModal()方法
showModal: function (postscollected,postcollected){ var that = this //這里調用了wx.showModal()方法 wx.showModal({ title: '收藏', content:postcollected?'是否收藏該篇內容?':'取消收藏該文章?', showCancel: "true", cancelText: "取消", confirmText: "確定", success:function(res){ if(res.confirm){ wx.setStorageSync("posts_collected", postscollected); //跟新數據綁定變量 that.setData({ collected: postcollected }) } } })
不同狀態之下點擊收藏按鈕出現如下效果:
收藏以后點擊按鈕:
原網址:https://blog.csdn.net/qq_40876689/article/details/80034886