WeChat applet parameter transfer

1. When the navigator jumps

wxml page ("&" is available when there are many parameters)

1

<navigator url='../index/index?id=1&name=aaa'></navigator>

  Or add a click event, js uses navigateTo to jump and pass parameters, the two effects are the same

 wx.navigateTo({
            url: '../index/index?id=1&name=aaa',
          })

The js page is directly obtained in onLoad

  onLoad: function (options) { 
     //Page initialization options are parameters brought by page jump 
     var id = options.id //Get value 

  },

2. Global variables

app.js page

globalData:{
      id:null
    }     

assignment:

var app = getApp(); 
app.globalData.id = 2

Value:

var app = getApp(); 
var id = app.globalData.id

3. List index subscript value

wxml page

1

<button bindtap='clickMe' data-id='1'>点击</button>

If you need to pass more than one, you can write multiple data-[parameters] to pass

js page

1

2

3

4

clickMe:function(e){

  var id = e.currentTarget.dataset.id

  console.log(id);

},

  Note : Set data-[parameter name] to pass parameters through wxml, [parameter name] can only be lowercase, not uppercase

4. form form pass value

The value passing in the form form is relatively simple and commonly used, so I won’t give an example

Guess you like

Origin blog.csdn.net/weixin_42748604/article/details/113885664