小程序倒計時遇到的問題


在實現倒計時功能時,遇到一個報錯:

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)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM