Data transfer of WeChat applet

Let me tell you first, it is essentially a string type transfer. However, for the transfer of objects and array collections, it is necessary to deal with the data when passing and the data after receiving.

1. Pass basic data types

index.js sends page JS

test.js accepts page JS

2, pass object {}

index.js sends page JS

test.js accepts page JS

The printed Log is as follows:

test.js [sm]:16 The received parameter is obj={"name":"I am name","extra":"I am extra"}

3, pass array collection[]

index.js sends page JS

test.js accepts page JS

The printed Log is as follows:

test.js [sm]:17 The received parameter is list=["item-A","item-B"]

In addition, you can also pass data through the cache (wx.setStorage(OBJECT), wx.setStorageSync(KEY, DATA)), but it needs to be cleared after saving to prevent the cache from being too large.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325263173&siteId=291194637