vue时间计时器从0开始

<div>
    <div>{{integerVal(hour)}}:</div>
    <div>{{integerVal(branch)}}:</div>
	<div>{{integerVal(second)}}</div>
</div>
export default {
		data() {
			return {
				showStar: null, //0未录制,1录制中,2录制完成
				numberStr: 0, //计数器
				timer1: null,
				second:0,
				branch:0,
				hour:0
			}
		},
		methods: {
			integerVal(number){
				if(number>=0 && number<=9){
					return ('0'+JSON.stringify(number))
				}else{
					return number;
				}
			},
			
			changeStar(val) {
				const that = this;
				that.showStar = val;
				if (that.showStar) { //开始
					that.second = 0;
					that.branch = 0;
					that.hour = 0;
					that.start();
				} else { //结束
					that.stop();
				}
			},

			start() {
				const that = this;
				that.timer1 = setInterval(() => {
					that.second = that.second+1;
					if(that.second==60){
						that.second = 0;
						that.branch = that.branch + 1;
						if(that.branch==60){
							that.branch = 0;
							that.hour = that.hour + 1;
						}
					}
					that.numberStr = that.numberStr + 1;
				}, 1000)
			},

			stop() {
				const that = this;
				clearInterval(that.timer1);
			}
		}
	}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值