uni 微信小程序定时器页面不更新
2021/5/18 1:25:18
本文主要是介绍uni 微信小程序定时器页面不更新,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
uni 编写微信小程序,uni中写定时器在小程序端会出现,页面更新不及时的情况
今天在项目中遇到了这个问题,苦苦找了2个小时,
下面以我在倒计时定时器中遇到的问题为例,如何去解决
for (let index in t.goodsList) { let timeLeave = new Date(t.goodsList[index].endTime).getTime() - new Date().getTime() if (timeLeave <= 0) { t.goodsList[index].goodhidden = true clearInterval(t.cutdownsetIntervalList[index]) t.cutdownsetIntervalList[index] = null return } t.cutdownsetIntervalList[index] = setInterval(function() { if (t.homeTagIndex !== 4) { clearInterval(t.cutdownsetIntervalList[index]) t.cutdownsetIntervalList[index] = null return } t.cutdownTimeList[index] = t.timeCl(t.goodsList[index].startTime, t.goodsList[index].endTime) t.$forceUpdate(); // console.log(t.cutdownTimeList[index]) // 这里输出的数据都会更新
一开始以为是定时器的问题,输出数据后发现,数据是每一秒中打印一次没有问题,
经过分析应该是微信小程序没有及时更新页面渲染,导致几秒钟才变更一次
for (let index in t.goodsList) { let timeLeave = new Date(t.goodsList[index].endTime).getTime() - new Date().getTime() if (timeLeave <= 0) { t.goodsList[index].goodhidden = true clearInterval(t.cutdownsetIntervalList[index]) t.cutdownsetIntervalList[index] = null return } t.cutdownsetIntervalList[index] = setInterval(function() { if (t.homeTagIndex !== 4) { clearInterval(t.cutdownsetIntervalList[index]) t.cutdownsetIntervalList[index] = null return } t.cutdownTimeList[index] = t.timeCl(t.goodsList[index].startTime, t.goodsList[index].endTime) t.$forceUpdate(); //这里让微信小程序强制更新数据就可以解决这个问题 // console.log(t.cutdownTimeList[index]) // 这里输出的数据都会更新
这篇关于uni 微信小程序定时器页面不更新的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-06-30实现小程序内部扫码签到和微信扫一扫签到-icode9专业技术文章分享
- 2024-06-30微信内调用扫码扫描小程序码如何解析链接-icode9专业技术文章分享
- 2024-06-30小程序码链接加密了如何解-icode9专业技术文章分享
- 2024-05-302024年最新版云开发cms开通步骤,开始开发微信小程序前的准备工作,认真看完奥!
- 2024-03-30微信小程序的网络设置,及网络请求:wx.request(OBJECT)
- 2024-01-22基于taro搭建小程序多项目框架
- 2024-01-13小程序开发:在插件市场寻找步骤条组件并二开
- 2024-01-05钉钉小程序生态—企业机器人加互动卡片,改善用户体验的开始!
- 2023-12-29【UniApp】-uni-app-打包成小程序
- 2023-12-26性能翻倍!京东亿级体量小程序优化实践