在實現倒計時功能時,遇到一個報錯:
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)