hi, 欢迎访问我的博客

小程序倒计时遇到的问题

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

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)

 

posted @ 2019-03-04 15:11  打静爵  阅读(4149)  评论(0编辑  收藏  举报