小程序倒计时遇到的问题

时间:2019-03-04 15:36:05   收藏:0   阅读:1282

在实现倒计时功能时,遇到一个报错:

setTimeout expects a function as first argument but got undefined.;at pages/limited-sale/limited-sale onReady function;at setTimeout callback function
TypeError: setTimeout expects a function as first argument but got undefined.

打印了下,结果看到函数是undefined的

技术分享图片

一看就知道这是this的指向问题了,将关键代码的定时器部分加下绑定就可以了:

this.timer = setTimeout(this.onTimeUp.bind(this), 1000)

 

原文:https://www.cnblogs.com/pjl43/p/10470813.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!