微信小程序API交互反饋,wx.showToast顯示消息提示框


導讀:wx.showToast(OBJECT) 顯示消息提示框。 OBJECT參數說明: 參數 類型 必填 說明 最低版本 title String 是 提示的內容 icon String 否 圖標,有效值"success"、"loading" image String 否 自定義圖標的本地路...

微信小程序API交互反饋,wx.showToast顯示消息提示框

wx.showToast(OBJECT)


顯示消息提示框。

OBJECT參數說明:

參數 類型 必填 說明 最低版本
title String 提示的內容  
icon String 圖標,有效值"success"、"loading"  
image String 自定義圖標的本地路徑,image 的優先級高於 icon 1.1.0
duration Number 提示的延遲時間,單位毫秒,默認:1500  
mask Boolean 是否顯示透明蒙層,防止觸摸穿透,默認:false  
success Function 接口調用成功的回調函數  
fail Function 接口調用失敗的回調函數  
complete Function 接口調用結束的回調函數(調用成功、失敗都會執行)  

示例代碼:

wx.showToast({
  title: '成功', icon: 'success', duration: 2000 })

wx.showLoading(OBJECT)


基礎庫版本 1.1.0 開始支持,低版本需做兼容處理

顯示 loading 提示框, 需主動調用 wx.hideLoading 才能關閉提示框

OBJECT參數說明:

參數 類型 必填 說明
title String 提示的內容
mask Boolean 是否顯示透明蒙層,防止觸摸穿透,默認:false
success Function 接口調用成功的回調函數
fail Function 接口調用失敗的回調函數
complete Function 接口調用結束的回調函數(調用成功、失敗都會執行)

wx.hideToast()


隱藏消息提示框

wx.hideLoading()


基礎庫版本 1.1.0 開始支持,低版本需做兼容處理

隱藏loading提示框

wx.showLoading({
  title: '加載中', }) setTimeout(function(){ wx.hideLoading() },2000)

wx.showModal(OBJECT)


​顯示模態彈窗

OBJECT參數說明:

參數 類型 必填 說明
title String 提示的標題
content String 提示的內容
showCancel Boolean 是否顯示取消按鈕,默認為 true
cancelText String 取消按鈕的文字,默認為"取消",最多 4 個字符
cancelColor HexColor 取消按鈕的文字顏色,默認為"#000000"
confirmText String 確定按鈕的文字,默認為"確定",最多 4 個字符
confirmColor HexColor 確定按鈕的文字顏色,默認為"#3CC51F"
success Function 接口調用成功的回調函數
fail Function 接口調用失敗的回調函數
complete Function 接口調用結束的回調函數(調用成功、失敗都會執行)

succes返回參數說明:

參數 類型 說明 最低版本
confirm Boolean 為 true 時,表示用戶點擊了確定按鈕  
cancel Boolean 為 true 時,表示用戶點擊了取消(用於 Android 系統區分點擊蒙層關閉還是點擊取消按鈕關閉) 1.1.0

示例代碼:

wx.showModal({
  title: '提示', content: '這是一個模態彈窗', success: function(res) { if (res.confirm) { console.log('用戶點擊確定') } else if (res.cancel) { console.log('用戶點擊取消') } } })

wx.showActionSheet(OBJECT)


​顯示操作菜單

OBJECT參數說明:

參數 類型 必填 說明
itemList String Array 按鈕的文字數組,數組長度最大為6個
itemColor HexColor 按鈕的文字顏色,默認為"#000000"
success Function 接口調用成功的回調函數,詳見返回參數說明
fail Function 接口調用失敗的回調函數
complete Function 接口調用結束的回調函數(調用成功、失敗都會執行)

success返回參數說明:

參數 類型 說明
tapIndex Number 用戶點擊的按鈕,從上到下的順序,從0開始

示例代碼:

wx.showActionSheet({
  itemList: ['A', 'B', 'C'], success: function(res) { console.log(res.tapIndex) }, fail: function(res) { console.log(res.errMsg) } })

Bug & Tip

  1. bug:Android6.3.30,wx.showModal 的返回的 confirm 一直為 true;
  2. tip: wx.showActionSheet 點擊取消或蒙層時,回調fail, errMsg 為 "showActionSheet:fail cancel";
  3. tip: wx.showLoading 和 wx.showToast 同時只能顯示一個,使用 wx.hideToast/wx.hideLoading 都可以關閉提示框;
  4. tipiOS wx.showModal 點擊蒙層不會關閉模態彈窗,所以盡量避免使用“取消”分支中實現業務邏輯。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM