Deprecated: Typecho\Widget\Request::getServer(): Implicitly marking parameter $default as nullable is deprecated, the explicit nullable type must be used instead in D:\PHP_HOME\www\gp_blog\var\Typecho\Widget\Request.php on line 219

Deprecated: Typecho\Request::getServer(): Implicitly marking parameter $default as nullable is deprecated, the explicit nullable type must be used instead in D:\PHP_HOME\www\gp_blog\var\Typecho\Request.php on line 349

Deprecated: Typecho\Widget\Response::goBack(): Implicitly marking parameter $suffix as nullable is deprecated, the explicit nullable type must be used instead in D:\PHP_HOME\www\gp_blog\var\Typecho\Widget\Response.php on line 158

Deprecated: Typecho\Widget\Response::goBack(): Implicitly marking parameter $default as nullable is deprecated, the explicit nullable type must be used instead in D:\PHP_HOME\www\gp_blog\var\Typecho\Widget\Response.php on line 158
开发者

遇到问题
请求api返回需要先登录,实际上登录已成功
想必大家在开发小程序的时候,肯定遇到了页面请求数据加载接口先执行,wx.login()登录接口后执行,导致请求接口返回请先登录,实际上登录确实成功的异常情况!

问题分析
在微信小程序中,由于app.js中的onLaunch和其他页面中js的onLoad属于异步执行。
有时onLaunch中会有网络请求,在等待网络返回值时,也就是还未执行完时,其他页面中js的onLoad已经执行了。这时就会导致页面中的onLoad函数没有获取到登录成功后的token以及其他必备参数,从而导致请求接口时,因为缺失必备参数获得的返回值异常的情况。

- 阅读剩余部分 -