小程序获取信息不同步,Console中输出结果有差异?

小程序 文章 2022-03-09 09:20 319 0 全屏看文

AI助手支持GPT4.0

小程序获取信息不同步,Console中输出结果有差异?The information obtained by the applet is not synchronized, and the output results in the console are different?

小程序获取信息不同步,Console中输出结果有差异?
框架类型 问题类型 终端类型 微信版本 基础库版本
小程序 Bug 工具 8.0.18 2.22.1

js文件:

(onLoad函数)

(onShow函数)


console结果:

(未展开。显示数据为空,导致onShow函数调用对应数据时为空数据)

(点击展开后,显示数据已经获取到)


预期结果:

在onLoad函数中对页面data进行初始化赋值,即获取数据。然后需要将数据传入onShow函数中使用。


请教各位大佬,这该如何解决呢?感谢~

Framework type problem type terminal type wechat version basic library version applet bug tool 8.0.18 2.22.1 JS file: (onload function) (Onshow function) console result: (not expanded. The display data is empty, resulting in the empty data when the Onshow function calls the corresponding data) (click to expand, the display data has been obtained) Expected result: initialize and assign the page data in the onload function, that is, obtain the data. Then you need to pass the data into the Onshow function for use. Ask you guys how to solve this problem? Thank you~

回答:

八九:

异步问题,可以百度了解下

VBit:

异步问题,了解一下js的执行方式

拾忆:

JS异步问题,可以考虑用 async/await 解决,具体百度下吧。

side alley - C 0 0:

现在想到的一种可能原因是,onLoad函数还没跑完的时候,就已经开始执行onShow了,因此导致onShow第一时间获取不到数据;而等到onLoad跑完后,页面数据才获取完毕。

-EOF-

AI助手支持GPT4.0