Home  >  Article  >  WeChat Applet  >  How to pass parameters and receive data in WeChat applet

How to pass parameters and receive data in WeChat applet

不言
不言Original
2018-08-10 16:56:209431browse

The content of this article is about the method of passing parameters and receiving data in the WeChat applet. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

When passing a string

//传递参数的jsclick:function(){
    var str='要传递的字符串';
    wx.navigateTo({
      url: '../page/index?str=' + str
    })
}//在下个页面的onload中获取,
  onLoad: function (options) {
    var str= options.str;    //接收到的参数    str为上个页面传递的key值
    console.log(options.str)
  }

When passing an object or an array, the processing method is the same. Pay attention to the processing between types

//传递参数的js    通过提供的JSON.stingify方法,将对象转换成字符串后传递
  click:function(){
    var objectModel={};    
    var model = JSON.stringify(objectModel);
    wx.navigateTo({
      url: '../page/index?model=' + model,
    })
  }//接收页面onLoad: function (options) {
    //将字符串转换成对象  model即为上个js中传递的key
    var objectModel = JSON.parse(options.model);   
  },1

Related recommendations:

Parsing of page compatible h5 tags in mini programs

Code parsing of app.json configuration in WeChat mini programs

Page layout, absolute positioning and button code in the mini program

The above is the detailed content of How to pass parameters and receive data in WeChat applet. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn