做小程序项目中,需要做一个倒计时功能,如下图: 记录一下实现步骤: 1.考虑到这个功能可能会有多处用到,所以把倒计时的函数写在utils.js里面: const formatNumber = n => { n = n.toString() return n[1] ? n : '0' + n } // 倒计时 function countDown(that) { //倒计时函数 let newTime = new Date().getTime(); let endTime = that.data.…
timeOut: function(time) { var that = this; var end = new Date(time).getTime(); var Interval = setInterval(function() { var start = new Date().getTime() var x = end - start; if (x > 0) { var seconds = x / 1000; seconds = parseInt(seconds); //秒数取整 var…