[Mini Program] The mini program scans different QR code parameters multiple times and does not take effect.

Sometimes the development of mini programs inevitably requires the function of scanning a QR code, and the QR code brings parameters to enter the specified page of the mini program. When scanning the QR code multiple times to enter, sometimes there will be problems with carrying parameters. One possibility that causes this may be that some friends misuse the API of the mini program.

First of all, we need to make it clear that there are two ways to obtain the mini program startup parameters.

1- wx.getLaunchOptionsSync()

        Get the parameters when the applet is started. Consistent with  the callback parameters of App.onLaunch  .

2 - wx.getEnterOptionsSync()

        Get the parameters when starting this applet. If it is a cold start, the return value   is consistent with the callback parameter of  App.onLaunch ; if it is a hot start, the return value  is consistent with App.onShow .

We all know that mini programs are divided into cold start and hot start

 

  • Cold start: If the user opens the mini program for the first time, or if it is opened again by the user after being destroyed, the mini program needs to be reloaded and started, that is, cold start.
  • Hot start: If the user has already opened a small program, and then opens the small program again within a certain period of time, the small program is not destroyed at this time, but only enters the foreground state from the background state. This process is a hot start.

From the perspective of the applet life cycle, the " start " we generally talk about refers specifically to cold start, and hot start is generally called background switching to foreground.

During a cold start, the opportunity triggers our onlauch, while a hot start triggers onshow.

Therefore, everyone has to decide based on their own needs whether they need to obtain the parameters when the cold start is started, or the parameters passed during the latest start.

Guess you like

Origin blog.csdn.net/wuguidian1114/article/details/124352238