WeChat Mini Program-wx.navigateTo({}) Jump page to carry object/array/complex data parameter (carry a complex object data parameter)

Preface

You can understand it as: carry a complex object data parameter to realize the jump page reception.

In WeChat Mini Programs, wx.navigateTo({})it is common to use APIs to carry parameters to jump pages, but today there is a requirement to carry a complex data. It is an array with N objects nested in it, and there is an array in the object.

solution

Use JSONtwo methods of objects:

  1. JSON.strtingify: The objectconversion of a string
  2. JSON.parse: parse the string into object.
/*
* [发送参数]
* 将对象解析为字符串
*/

wx.navigateTo({
    
    
     url: '/pages/index?data=' + JSON.stringify(object),
})
/*
* [接收参数]
* 将字符串解析为对象
*/

this.setData({
    
    
	data: JSON.parse(options.data)
})

Precautions

You need to pay particular attention to the first , if there is an image link, it must be triggered, resolve to follow the tutorial.

  1. If there is a string transformed "?","&"或"="and other such symbols, only the symbols passed the previous string symbol after the data will be lost, I guess the question might be a small internal routing procedures to deal with these symbols sensitive to it. So sometimes we'll let you use encodeURIComponent()transcoding, and then in the target page decodeURIComponent()decode, so you can avoid data lost. If you do not understand, please visit the detailed code tutorial!
  2. Do not use parameters objectto use variables to save up and then passed, so when writing received may not be resolved successfully.

Guess you like

Origin blog.csdn.net/weixin_44198965/article/details/108872852