小程序倒计时遇到的问题

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

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)

猜你喜欢

转载自www.cnblogs.com/pjl43/p/10470813.html