vue计时器代码和倒计时代码

您所在的位置:网站首页 新年倒计时秒表 vue计时器代码和倒计时代码

vue计时器代码和倒计时代码

2024-01-19 10:48| 来源: 网络整理| 查看: 265

计时器 {{ time }} 开始 停止 export default { data() { return { time: "00:00:00", timer: null, seconds: 0, minutes: 0, hours: 0, }; }, methods: { start() { this.timer = setInterval(() => { this.seconds++; if (this.seconds === 60) { this.seconds = 0; this.minutes++; } if (this.minutes === 60) { this.minutes = 0; this.hours++; } this.time = `${this.formatTime(this.hours)}:${this.formatTime( this.minutes )}:${this.formatTime(this.seconds)}`; }, 1000); }, stop() { clearInterval(this.timer); }, formatTime(time) { return time { time }} 开始 停止 export default { data() { return { time: "00:00:00", timer: null, remainingTime: 0, }; }, methods: { start() { const endTime = Date.now() + this.remainingTime; this.timer = setInterval(() => { const remainingTime = endTime - Date.now(); if (remainingTime const hours = Math.floor(remainingTime / 3600000); const minutes = Math.floor((remainingTime % 3600000) / 60000); const seconds = Math.floor((remainingTime % 60000) / 1000); this.time = `${this.formatTime(hours)}:${this.formatTime( minutes )}:${this.formatTime(seconds)}`; } }, 1000); }, stop() { clearInterval(this.timer); }, formatTime(time) { return time


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3