(1)wx.showToast 消息提示框
這里要注意一下代碼的注釋,icon目前只支持 "success" 和 "loading",如果想要去除圖標(biāo)的話,設(shè)置 icon:'none';
另外微信小程序官方還給出了一個(gè)屬性 mask ,默認(rèn)為 false,沒(méi)有實(shí)際顯示效果,透明蒙層,防止觸摸穿透
wx.showToast({
title: '成功',
icon: 'success' ,//只支持"success"、"loading" ,默認(rèn)success,去除圖標(biāo)用 none
image:'', //自定義圖標(biāo)的本地路徑,優(yōu)先級(jí)高于 icon
duration: 1000,
success: function() {}
})
(2)wx.showModal消息模態(tài)框
wx.showModal({
title: '標(biāo)題',
content: '選擇確定或者取消?',
success (res) {
if (res.confirm) {
console.log('點(diǎn)擊了確定')
} else if (res.cancel) {
console.log('點(diǎn)擊了取消')
}
}
})
success 回調(diào)函數(shù):
success 回調(diào)函數(shù)
注意:
1、Android 6.7.2 以下版本,點(diǎn)擊取消或蒙層時(shí),回調(diào) fail, errMsg 為 "fail cancel";
2、Android 6.7.2 及以上版本 和 iOS 點(diǎn)擊蒙層不會(huì)關(guān)閉模態(tài)彈窗,所以盡量避免使用「取消」分支中實(shí)現(xiàn)業(yè)務(wù)邏輯
(3)wx.showLoading - wx.hideLoading
loading 提示框。需主動(dòng)調(diào)用 wx.hideLoading 才能關(guān)閉提示框;
同樣也包含屬性 mask;
wx.showLoading 和 wx.showToast 同時(shí)只能顯示一個(gè);
wx.showLoading({
title: '加載中'
})
setTimeout(function () {
wx.hideLoading()
}, 2000)
(4)wx.showActionSheet 操作菜單
wx.showActionSheet({
itemList: ['選項(xiàng)一', '選項(xiàng)二', '選項(xiàng)三'],
success (res) {
console.log(res.tapIndex)
},
fail (res) {
console.log(res.errMsg)
}
})
- itemList 為數(shù)組,最大長(zhǎng)度為6;
- tapIndex 為用戶點(diǎn)擊的序號(hào),順序從上到下,從0開(kāi)始;
- 與 wx.showModal 模態(tài)框一樣,需要注意回調(diào)fail,詳情查看 第二點(diǎn) 內(nèi)引用的微信官方的部分;
(5)wx.hideToast 隱藏消息提示框
參數(shù)僅包含 success、fail、complete;
目前這段測(cè)試代碼是放在wx.showToast后面進(jìn)行測(cè)試的,可以正常執(zhí)行。
setTimeout(function(){
wx.hideToast({
success () {
console.log("hideToast")
},
fail () {
console.log("hideToast.fail")
}
})
},2000)

總結(jié)