Personal learning experience for quick start of WeChat applet (1)

1. Data binding on the interface layer

1.1 Where is the data

The data is in the data attribute of the current page (xxxx.js) object.

1.2 Where to bind to

Use it wherever you want, output in { {}} syntax
Example 1

2. About list rendering

Define an object array in the data attribute of the current page (xxxx.js)
Insert picture description here
and then in the corresponding xxxx.wxml
Insert picture description here
so that the following display can be displayed.
Insert picture description here
However, this code is cumbersome, we can use wx:for to dynamically obtain:
Insert picture description here
where item represents the current Elements of the page being traversed, you can use wx:for-item to alias the elements currently being traversed
Insert picture description here
Insert picture description here

3. About the incident

The basic event is used by adding a "bind + event name" attribute to the component , and the value of the attribute points to a js method defined in the current page object . which is:

<button bindtap="buttonTapHandle">点我</button>

The bind+ event is bindtap, and the specified method is buttonTapHandle
Insert picture description here
Insert picture description here
event bubbling. Clicking on blue is equivalent to clicking on red, because blue is inside red, and sometimes we need to prevent bubbling. Can catch + event name
Insert picture description here
event parameter passing
Insert picture description here
Insert picture description here
Insert picture description here
data stream Insert picture description here
from back to front can be { to pass values {}}

  <view class="container">
    <input value="{
     
     {message}}" bindinput="inputHandle"/>
    <text>{
   
   {message}}</text>
  </view>

From front to back, the input event is monitored, and then the value is passed through setData

  inputHandle: function(e){
    
    
      this.setData({
    
    
        message:e.detail.value
      })
  }

4. A simple login case

This is the page to be completed. We mainly write the logical code.
Insert picture description here
First , we
need to design the data structure, which is the data attribute in js.
According to the page, we need a username and a password attribute
Insert picture description here
and then we
need to bind the data to the specified element. (Use **{ {}}**), add a click event to the button, and write the corresponding logic.
Insert picture description here
Because the judgment function of the username and password is similar, we can abstract it out.
It is worth noting that in the applet, you cannot define the passing parameters yourself. If you want to pass the parameters, you need to use DataSet.
When you know the attribute name, you can get the value through xxxx. attribute name, and when you don’t know it, you can get the value through xxxx [object name].
Insert picture description here
Insert picture description here
Get our custom attributes through dataset (the name is the same before and after the agreement), target is the object that triggers the current event.
Insert picture description hereInsert picture description here
from form component
The attribute in the form that wants to be submitted must have a name attribute and a submit button.
Insert picture description here

5. Conditional rendering

Use wx:if

Guess you like

Origin blog.csdn.net/zcylxzyh/article/details/112753265