小程序启动状态下,再扫码进入,不会走onLaunch?

小程序 文章 2022-01-27 17:40 1191 0 全屏看文

AI助手支持GPT4.0

小程序启动状态下,再扫码进入,不会走onLaunch?When the applet is activated, scan the code to enter, will it not go to onLaunch?

小程序启动状态下,再扫码进入,不会走onLaunch?

之前把处理扫码的业务逻辑放在onLaunch里处理的,结果发现,小程序启动状态下,扫码进来,不走该生命周期。

那换成onShow来处理扫码业务逻辑,就可能触发多次重复处理多次。

怎么处理好一些,其实我就想扫码进来把业务逻辑处理了,然后后面不管怎么样都不再重复处理了。

之前着急还专门有个扫码解析页,扫码进来统一跳转解析参数,解析redirct目标页,特别不好的地方因为参数长度32位的限制, 所以生成小程序码前把参数存在后端返回token,解析页再请求后端拿到对应的参数,参数里有目标页,再redirct。

有更好的处理办法吗,你们是怎么处理的。

Previously, the business logic for code scanning was processed in onlaunch. It was found that when the applet was started, the code scanning came in and did not go through the life cycle. If Onshow is used to process the code scanning business logic, it may trigger repeated processing for many times. How to handle it better? In fact, I want to scan the code to deal with the business logic, and then I won't repeat it anyway. In the past, there was a code scanning analysis page. The code scanning came in to uniformly jump the analysis parameters and analyze the redirct target page. It is particularly bad because the parameter length is limited by 32 bits, so before generating the applet code, the parameters are stored in the back end and returned to the token. The analysis page then requests the back end to get the corresponding parameters. There is a target page in the parameters and redirct. Is there a better way to deal with it? How did you deal with it.

回答:

老张:

1、热启动不走。

李伟豪:

那换成onAppShow来处理扫码业务逻辑,就可能触发多次重复处理多次。

-----------

你可以在onAppShow处理,然后在存一个标识,表示已处理。下次热启动有标识时,就不再执行


潘多拉魔盒与好奇心:目前按这个逻辑去处理的,但是可能还要处理扫不同的码获取不同的参数问题,保存不同的参数的处理标识。更复杂一些,还跟登录态有关,不登录先存着,后面登录后再调用。越来越复杂,只是想有没有更好的处理办法。
圣殿骑士:

onlaunch是监听初始化的,换成 onshow 试下

如果想深入了解,可以看这篇文章

https://developers.weixin.qq.com/community/develop/article/doc/00002ac57208f0e7335d111f156013

-EOF-

AI助手支持GPT4.0