处理异步操作时,处理的值渲染不上页面,AppData的值已经修改了页面上的值未修改?

小程序 文章 2021-04-01 16:02 409 0 全屏看文

AI助手支持GPT4.0

处理异步操作时,处理的值渲染不上页面,AppData的值已经修改了页面上的值未修改?When processing asynchronous operations, the processed value cannot be rendered on the page, and the value of AppData has been modified. The value on the page has not been modified?

处理异步操作时,处理的值渲染不上页面,AppData的值已经修改了页面上的值未修改?



从接口接收数据修改数据出现异步问题,把异步变同步后,值已修改,但页面的位置没有变化还是从接口传的位置

There is an asynchronous problem when receiving data from the interface to modify the data. After changing the asynchronous to synchronous, the value has been modified, but the position of the page has not changed, and it is still the position transferred from the interface

回答:

张有釜:

两点拙见

1.封装的promise有问题 应该在合适的带有异步操作的出口处 return resolve或reject

2.建议不要循环请求 尽量批量拉取信息

z范凯:


    wx.nextTick(() => {      this.setData({ number: 3 }) // 在当前同步流程结束后,下一个时间片执行    })


Mr.Zhao:

这里异步了

-EOF-

AI助手支持GPT4.0