Data transfer method of WeChat applet

1. The data on a page is transferred from the view layer to the logic layer. You can set a certain value in the form of the data-xx attribute of the label, and then use currentTarget.dataset.xx to take it out in the logic layer . (In view of the difference between currentTarget and target , only a certain attribute of the element bound to the event is valued)

2. Data transfer from the logic layer to the view layer, using

this.setData({ 
    nameInWXML : nameInJS 
})

Assign the value obtained in a certain method of js to a new parameter whose name is stored in the js file

data:{
    nameInWxml: ""
 }

In, and can be used in the wxml page

<view>{
   
   { nameInWXML }}</view>

To get it.

3. Passing values ​​between two different js pages: Here we use wx.navigateTo as the jump method, depending on the situation.

transfer:

wx.navigateTo({ 
    url:"../index/index?id=" + this.data.name
}) 

Here, the name stored in the page data will be passed to the index page as the id.

Receive: In the onLoad method of the receiving page index,

onLoad: function(options){ 
    console.log(options.id);
}

  You can directly get the passed parameter named id.

4. To pass multiple parameters on different pages: use "+" to  connect the two values.

wx.navigateTo({ 
    url:"../index/index?id=" + this.data.name + "&sex=" + this.data.sex 
})

  In this way , the two values id = this.data.name and sex = this.data.sex are passed to the index page.

  In the same way, use

onLoad: function(options){ 
    console.log(options.id);
    console.log(options.sex);
}

  You can get the value passed in.

Guess you like

Origin blog.csdn.net/michaelxuzhi___/article/details/100589596