# Tap event
Lift the user up after the mobile end finger is pressed, or in the tool/The PC side is defined as a time to lift after pressing the mouse Tap event. The tap event is basically based on the web Standard touch Event to do the encapsulation.
# Click state
To prevent the misuse of sensitive interfaces, part API When triggered, the click state is checked and consumed (e.g. wx.openSetting, wx.requestSubscribeMessage), and when the click state fails, the corresponding function is affected (call failure or degradation).
Each time the user clicks, the corresponding tap The event response function for the event gets the click state. In addition, the following API There are also click-states within the callback:
- wx.requestPayment and Wx.requestOrderPayment, but these two API The obtained click state cannot be used to trigger Wx.openembeddedminiprogram, details are availableThe ability to open a half-screen Mini Program after payment of the relevant adjustment notice
- wx.showModal and Wx.showactionsheet, the click state is only used in the success After a successful callback or interface call complete Get in.
Click states are only valid within the macro task in which the current event response function is located. Therefore, setTimeout/setInterval The wrapped function does not have click-state, but Promise/async/await Inside effective.
Because iOS of Promise Implementation is problematic, the Mini Program uses polyfill of Promise。so iOS Under Use Promise/async/await Will lose the click state:
// <button bind:tap="handleTap" >tap</button>
handleTap: async () => {
// Clickable state
setTimeout (() => {
// Loss of click-state
}, 100)
Promise.resolve().then(() => {
// Android With a click state, iOS Loss of click-state on
})
}
in tap Making asynchronous requests in event handlers is a common behavior. when wx.request、wx.downloadFile or wx.getSetting Has a click state when called, it will continue the click state to success/complete/fail Callback function:
// <button bind:tap="handleTap" >tap</button>
handleTap: async () => {
// Clickable state
wx.request({
url: "https://www.thissitedoesnotexist.com /step1",
complete: () => {
// Clickable state
wx.request({
url: "https://www.thissitedoesnotexist.com /step2",
complete: () => {
// Clickable state
},
})
},
})
}
Single tap After the generated click state is consumed, the click state cannot be continued:
// <button bind:tap="handleTap" >tap</button>
handleTap: async () => {
// Clickable state
wx.openSettings({}) // Successful call
wx.request({
url: "https://www.thissitedoesnotexist.com ,
complete: () => {
// Loss of the click-state, because the click state is wx.openSettings Consumed.
},
})
wx.openSettings({}) // Successful call
}