1. 程式人生 > >微信小程式之介面互動反饋

微信小程式之介面互動反饋

互動反饋就是在使用者觸發某事件之後,給使用者一個反饋資訊。

在小程式中是通過以下幾種方式實現的:

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函式,裡面呼叫了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 }) } } })

不同狀態之下點選收藏按鈕出現如下效果:

收藏以後點選按鈕:


第一次寫部落格,希望自己說清楚了 ,以後當筆記看!