The first question: how to pass data between small program pages?

When A jumps to B, the data can be passed through the QUERY in the URL.

Options in the onLoad(Options) method on the page will contain the key-value content in the query.

If we need to pass structured data such as JSON or array, we can string and encode the structured data first, and then pass it in this way.

encodeURIComponent(JSON.stringify(xxx))
Copy the code

In page B, after obtaining the content, the data is analyzed by the following methods.

JSON.parse(decodeURIComponent(xxx))
Copy the code

Second question: how to return data between pages?

Let’s say A opens B, and some data in B needs to be transferred to A. You can get the previous page instance and then call the previous page method directly for data transfer.

const pages = getCurrentPages();
const prevPage = pages[pages.length - 2];
prevPage.methodOfPrevPage(data);
Copy the code

The third question: how does the small program keep a session with the server?

The applet framework has no Cookie management mechanism, and the applet does not provide a way to set cookies to the WebView. Therefore, if we want to continue to use the session-cookie mechanism, we need to implement a set of our own. We can simply extract the valid Cookie content in the set-cookie header, store it in memory and local, and assemble these cookies for use in the next request. When it comes to WebViews, we can use the query method to pass these Cookie contents to the Web side to maintain a valid session with the server side.

Of course, you can also use the Token mechanism to maintain a session with the server.

Question 4: How do I call a method in a child component?

We can add an ID to our custom component and then use the following method in our JS code:

this.selectComponent('#id').methodOfComponent(data);
Copy the code

Fifth question: how does a child component call a parent component’s method?

Using component Event methods, detailed in Component Event Documentation

When a child component is used in a parent component, you can define one

bind:customMethod='parentMethod'
Copy the code

Then in the child component, you can use the following code to call the method of the parent class

this.triggerEvent('customMethod', data);
Copy the code

Sixth question: how to do small program data analysis?

Small program background provides data analysis capabilities, specifically visible: “Small Program Data Analysis Documents”

And if you need to access the data to your own services, you can also get the data by calling the wechat interface: “Small Program Data Analysis Interface Document”

If we need custom data, we can call the method in the applet:

wx.reportAnalytics(eventName, data)
Copy the code

However, before use, need to create a new event in the small program management background custom analysis, configure the event name and field. In addition, the data of custom events cannot be obtained through the interface.

So if you want to share custom events on your own server, you’ll have to develop your own interfaces.

Seventh question: Wechat small program two-dimensional code generation times limit?

Wechat provides three ways to generate wechat QR code, details can be viewed: “Small program QR Code related Documents”

The three types of QR codes need to be generated by the server by invoking the wechat interface through access_token. And interface B can only generate the TWO-DIMENSIONAL code of the published applets page, so your applets must be online before you can test this function. A little pit.

Interfaces A, and C have the number limit, and the total number of codes generated by interfaces A and C is limited to 100,000.

The number of calls to interface B is unlimited, but the frequency is limited: 5000 calls per minute.

Interface A and interface C can pass A path of up to 128 bytes relative to interface B. You can pass an argument in the path as A query.

Interface B divides PATH into page and scene relative to A and C, where scene is A maximum of 32 characters. You can get the scene in the onLoad method on the page using options. Scene.

Eighth question: ordinary TWO-DIMENSIONAL code can open small program?

Yes, it needs to be added in the small program management background. After being added, you can scan the TWO-DIMENSIONAL code of the following content to jump to the specified page of the small program.

Details can be viewed: “Small program common TWO-DIMENSIONAL code Document”

Question nine: how is the small program version compatible?

Small programs run on wechat, and the basic library of small programs is released with the wechat version. So different versions of wechat will have an impact on the performance of small programs. See the following links for coverage of the base libraries for each version. Introduction to the Basic Mini Program Library Version

At present, the lowest basic library version recommended by wechat can cover more than 80% of wechat users. In addition, the low version of wechat in the use of high basic library version of the small program will prompt to upgrade wechat.

Q 10: Can small program code run in a browser?

Small program is using a set of their own framework, just borrow the current mainstream HTML + JS + CSS development form, so small program code itself is not directly run in the browser.

At present, Meituan open source a set of its own solution: MPVUE, using the form of VUE to write small programs. And you can change the packaging configuration so that the same set of code can run in both the applet and the browser.

Recently, I have made several small programs in the company, and I have some experience in small program development. If you have more questions about small program development, you can join the small program developers to exchange wechat groups and learn together.