Learning WeChat Mini Program (3)

A way to pass data to the click event callback function is
Insert picture description here
data-fixed, you can write anything later, and then you can go to the corresponding event object to get it.
Here is the same as vue, just pass the index to the following, and then pass the index to the callback function for use.
Insert picture description here
Here you can get the index value from currentTarget.dataset.index
and pass it to the
Insert picture description here
corresponding interface in this way . Options in the onload of the corresponding interface The passed parameters
Insert picture description here
Insert picture description here
will be received in the form of objects so that we can import data, read them, and click on the corresponding interface to display the corresponding data.

The difference between target and currentTarget:
event.target is the element that triggers the event, currentTarget is the current element.

This place is a bit like event delegation.
To summarize the rules:
1. This kind of click is bound to the external container, and then the click index is obtained through event.target Value
Insert picture description here
Insert picture description here
2. This is bound to itself, so event.currentTarget is required to get the index
Insert picture description here
Insert picture description here
here. Add the click event to pass the value data-custom name. This value seems to exist in the dataset, which is the difference between currentTarget and target. , Under the habit, the first contact.

In Vue, the data data will be proxyed to the instance. There is no small program, so this.data. is required to get the value.
Moreover, in the development of WeChat applets, in order to reduce the inconsistency between data and view layer data, all values ​​are modified by the setData method.
Modifying this.data directly without calling this.setData will not change the state of the page, and will also cause data inconsistency.

Collection effect:
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_46013619/article/details/104674076