Events in the Basics of Mini Program Development (9)
As mentioned earlier, the WeChat applet framework is a design method for analyzing the logic layer and UI layer. This design method needs to solve two problems
The UI layer responds to changes in the logic and data of the logic layer
The UI layer feeds back the user's operations to the logic layer
The data binding mentioned earlier solves the first problem, and eventTo solve the second problem
What is an event
Events are the communication method from the view layer to the logic layer.
Events can feed back user behavior to the logic layer for processing.
Events can be bound to components. When the trigger event is reached, the corresponding event processing function in the logic layer will be executed.
Event objects can carry additional information, such as id, dataset, touches.
To summarize, an event refers to something happening, usually when the user performs some operation, such as clicking a button or sliding a finger on the phone screen. When an event occurs, the framework calls the event handling function (if any) so that it can respond to user operations.
Event Binding
Complete the response to user operations through event binding. For example, to handle the tap
event of the view tag, in the tag Add bindtap = 'tapName'
to the attribute, and then add tapName
function in .js
//wxml <view id="tapTest" data-hi="WeChat" bindtap="tapName"> Click me! </view> //.js Page({ tapName: function(event) { console.log(event) } })
The event object contains some data about the event:
target: the component that triggered the event
currentTarget: the current component
type: event type
timeStamp: timestamp ( The number of milliseconds that elapsed between the page opening and the event being triggered)
touches: an array containing touch points (multi-touch)
changedTouches: the changed touch points Array (multi-touch)
detail: additional custom information
Bubble events and non-bubble events
Why is there# The difference between ##target and currentTarget is because events are divided into two categories, bubble events and non-bubble events
Bubbling events: When an event on a component is triggered, the event will be passed to the parent node.TheNon-bubbling events: When an event on a component is triggered, the event will not be delivered to the parent node.
tap event is a bubbling event (this is why event in the above example contains currentTarget), and in addition Other bubbling events include | Type| Trigger Condition|
| ------------- |-------------|
| touchstart | The finger touch action starts|
| touchmove| The finger moves after touching|
| touchcancel| The finger touch action is interrupted, such as incoming call reminder, pop-up window|
| touchend| The finger touch action ends |
| tap | Leave immediately after touching the finger |
| longtap | Leave after more than 350ms after touching the finger |
catch event binding, such as catchtap, you can prevent the bubbling behavior of events.
You can use the following code example to deepen your understanding of bubbling events//.wxml <view id="outter" bindtap="handleTapOutter"> 我是父亲节点 <view id="middle" catchtap="handleTapMiddle"> 我是儿子节点 <view id="inner" bindtap="handleInner"> 我是孙子节点 </view> </view> </view> //.js Page({ handleTapOutter: function(event) { console.log("父亲节点被点击") }, handleTapMiddle: function(event) { console.log("儿子节点被点击") }, handleInner: function(event) { console.log("孙子节点被点击") }, })
The above is the detailed content of Events in the Basics of Mini Program Development (9). For more information, please follow other related articles on the PHP Chinese website!

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics


![Event ID 4660: Object deleted [Fix]](https://img.php.cn/upload/article/000/887/227/168834320512143.png?x-oss-process=image/resize,m_fill,h_207,w_330)
Some of our readers encountered event ID4660. They're often not sure what to do, so we explain it in this guide. Event ID 4660 is usually logged when an object is deleted, so we will also explore some practical ways to fix it on your computer. What is event ID4660? Event ID 4660 is related to objects in Active Directory and will be triggered by any of the following factors: Object Deletion – A security event with Event ID 4660 is logged whenever an object is deleted from Active Directory. Manual changes – Event ID 4660 may be generated when a user or administrator manually changes the permissions of an object. This can happen when changing permission settings, modifying access levels, or adding or removing people or groups

On iPhones running iOS 16 or later, you can display upcoming calendar events directly on the lock screen. Read on to find out how it's done. Thanks to watch face complications, many Apple Watch users are used to being able to glance at their wrist to see the next upcoming calendar event. With the advent of iOS16 and lock screen widgets, you can view the same calendar event information directly on your iPhone without even unlocking the device. The Calendar Lock Screen widget comes in two flavors, allowing you to track the time of the next upcoming event, or use a larger widget that displays event names and their times. To start adding widgets, unlock your iPhone using Face ID or Touch ID, press and hold

When a value is added to the input box, the oninput event occurs. You can try running the following code to understand how to implement oninput events in JavaScript - Example<!DOCTYPEhtml><html> <body> <p>Writebelow:</p> <inputtype="text"

How to implement calendar functions and event reminders in PHP projects? Calendar functionality and event reminders are one of the common requirements when developing web applications. Whether it is personal schedule management, team collaboration, or online event scheduling, the calendar function can provide convenient time management and transaction arrangement. Implementing calendar functions and event reminders in PHP projects can be completed through the following steps. Database design First, you need to design a database table to store information about calendar events. A simple design could contain the following fields: id: unique to the event

PHP's page jump and routing management in mini program development With the rapid development of mini programs, more and more developers are beginning to combine PHP with mini program development. In the development of small programs, page jump and routing management are very important parts, which can help developers achieve switching and navigation operations between pages. As a commonly used server-side programming language, PHP can interact well with mini programs and transfer data. Let’s take a detailed look at PHP’s page jump and routing management in mini programs. 1. Page jump base

jQuery is a popular JavaScript library that can be used to simplify DOM manipulation, event handling, animation effects, etc. In web development, we often encounter situations where we need to change event binding on select elements. This article will introduce how to use jQuery to bind select element change events, and provide specific code examples. First, we need to create a dropdown menu with options using labels:

PHP permission management and user role setting in mini program development. With the popularity of mini programs and the expansion of their application scope, users have put forward higher requirements for the functions and security of mini programs. Among them, permission management and user role setting are An important part of ensuring the security of mini programs. Using PHP for permission management and user role setting in mini programs can effectively protect user data and privacy. The following will introduce how to implement this function. 1. Implementation of Permission Management Permission management refers to granting different operating permissions based on the user's identity and role. in small

How to develop and publish mini programs in uni-app With the development of mobile Internet, mini programs have become an important direction in mobile application development. As a cross-platform development framework, uni-app can support the development of multiple small program platforms at the same time, such as WeChat, Alipay, Baidu, etc. The following will introduce in detail how to use uni-app to develop and publish small programs, and provide some specific code examples. 1. Preparation before developing small programs. Before starting to use uni-app to develop small programs, you need to do some preparations.
