


WeChat Mini Program Practical Development View Layer WXML: Events
The previous article explained data binding, templates, logic, etc. The main function is to display data in the view and how to display it. But presentation is not enough, we need interaction. For example, an HTML page can display text and pictures, but it also needs some interactions, such as links, buttons, etc.
Interaction is actually an event. For example, onClick of button in HTML is the action triggered when clicked and the developer's corresponding business logic processing.
1. Event example: bindtap
Events are the communication method from the view layer to the logic layer. Feedback the user's behavior to the logic layer for processing. It is generally bound to a component, executes the processing function when triggered, and can carry parameters.
Make a button to jump to the page.
index.wxml:
View Layer WXML: Event
index.js:
toEvent : function(){
## // Jump to event.wxml page
wx.navigateTo({ url: '/pages/wxml/event'
})
}
Effect animation
Bubble event:
## When an event on a component is triggered, the event Will be passed to the parent node.
Non-bubbling events:
When an event on a component is triggered, the event will not be passed to the parent node.
The following are bubbling events, other component events are non-bubbling events without special declaration
Trigger event | ||||||||||||||||||||||||||||||
Finger touch action starts | ||||||||||||||||||||||||||||||
Finger moves after touching | ||||||||||||||||||||||||||||||
Finger touch action is interrupted, such as incoming call reminder, pop-up window | ||||||||||||||||||||||||||||||
The finger touch action ends | tap | |||||||||||||||||||||||||||||
longtap | ||||||||||||||||||||||||||||||
After touching the finger, leave after more than 350ms |
For example:
##The event starts with bind or catch #bind event binding does not prevent bubbling events from bubbling upwards, such as bindtap. catch event binding can prevent bubbling events from bubbling upward, such as catchtap. ##Because handleTap2 is a catchtap, so: Click on the inner view, Will trigger handleTap3, handleTap2. Clicking the middle view will trigger handleTap2 ##. Clicking the outer view will trigger handleTap1 ##.
##You can see the event execution log and event object.
3. Event Object Unless otherwise specified, when a component triggers an event, the handler function bound to the event by the logic layer will receive an event object. (See picture above, event object)
|

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software