Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat small program API interactive feedback


May 19, 2021 WeChat Mini Program Development Document


Table of contents


wx.showToast(OBJECT)

Displays a message prompt box.

OBJECT parameter description:

Parameters Type Required Description The lowest version
title String Is The contents of the prompt
icon String Whether icon, valid values "success," "loading"
image String Whether The local path of the custom icon, image, takes precedence over icon 1.1.0
duration Number Whether Prompt delay time in milliseconds, default: 1500
mask Boolean Whether Whether transparent mask is displayed to prevent touch penetration, default: false
success Function Whether The interface calls a successful callback function
fail Function Whether The interface calls the failed callback function
complete Function Whether Callback function at end of interface call (call succeeds, fails are executed)

Example code:

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

wx.showLoading(OBJECT)

Base library version 1.1.0 starts to support, and low versions need to be compatible

The loading prompt box is displayed and you need to actively call wx.hideLoading to close the prompt box

OBJECT parameter description:

Parameters Type Required Description
title String Is The contents of the prompt
mask Boolean Whether Whether transparent mask is displayed to prevent touch penetration, default: false
success Function Whether The interface calls a successful callback function
fail Function Whether The interface calls the failed callback function
complete Function Whether Callback function at end of interface call (call succeeds, fails are executed)

wx.hideToast()

Hide the message prompt box

wx.hideLoading()


Base library version 1.1.0 starts to support, and low versions need to be compatible

Hide the loading prompt box

wx.showLoading({
  title: '加载中',
})

setTimeout(function(){
  wx.hideLoading()
},2000)

wx.showModal(OBJECT)

Show modal spring windows

OBJECT parameter description:

Parameters Type Required Description
title String Is The title of the prompt
content String Is The contents of the prompt
showCancel Boolean Whether Whether to display the cancel button, the default is true
cancelText String Whether The text of the cancel button, which defaults to Cancel, up to 4 characters
cancelColor HexColor Whether The text color of the cancel button, which defaults to #000000.
confirmText String Whether Determines the text of the button, which defaults to OK, up to 4 characters
confirmColor HexColor Whether Determine the text color of the button, which defaults to #3CC51F
success Function Whether The interface calls a successful callback function
fail Function Whether The interface calls the failed callback function
complete Function Whether Callback function at end of interface call (call succeeds, fails are executed)

Succes returns a description of the parameters:

Parameters Type Description The lowest version
confirm Boolean True indicates that the user clicked the OK button
cancel Boolean When true, it means that the user clicked Cancel (for Android systems to distinguish between clicking on the mask off or clicking on the cancel button off) 1.1.0

Example code:

wx.showModal({
  title: '提示',
  content: '这是一个模态弹窗',
  success: function(res) {
    if (res.confirm) {
      console.log('用户点击确定')
    } else if (res.cancel) {
      console.log('用户点击取消')
    }
  }
})

wx.showActionSheet(OBJECT)

Displays the action menu

OBJECT parameter description:

Parameters Type Required Description
itemList String Array Is An array of text for a button, with a maximum length of 6
itemColor HexColor Whether The text color of the button, which defaults to #000000.
success Function Whether The interface calls a successful callback function, as detailed in the return parameter description
fail Function Whether The interface calls the failed callback function
complete Function Whether Callback function at end of interface call (call succeeds, fails are executed)

Success returns a description of the parameters:

Parameters Type Description
tapIndex Number The user clicks the button, in top-to-bottom order, starting at 0

Example code:

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

Bug & Tip

  1. bug : Android 6.3.30 wx.showModal returns a check that has always been true;
  2. tip : wx.showActionSheet click cancels or masks when the callback fail err Msg as "showActionSheet: fail cancel";
  3. tip : wx.showLoading and wx.showToast can only show one at a time, using wx.hideToast/wx.hideLoading can turn off the prompt box;
  4. tip iOS wx.showModal clicking on the mask does not close the modal spring window, so try to avoid implementing business logic in the Cancel branch.