思路:使用setInterval一直調用獲取當前時間方法javascript
setInterval(getCurrentTime, 1000) getCurrentTime () { let now = new Date (); let hh = now.getHours(); let mm = now.getMinutes() > 10 ? now.getMinutes() : '0'+now.getMinutes(); let ss = now.getSeconds() > 10 ? now.getSeconds() : '0'+ now.getSeconds(); this.currentTime = hh + ':' + mm + ':' + ss }