首页 |  我的博客 |  查看该博主内容分类 | 

el-statistic的suspend停止计时方法使用示例

前言

官方给的例子不太完整,照着使用可能会不起作用,因此研究了下源码,得出了该例,亲测可用。

注:...省略号指基本的属性常规写即可,例子写出的属性是必须属性

html

<el-statistic ...
			  ref="countDownModule"
			  :value="countDownTIme"
			  ...
			  >
	<template slot="prefix">
		倒计时:
	</template>
</el-statistic>
<el-button @click="stopCountDown">{{stop?'开始':'停止'}}</el-button>

javaScript

export default {
	data(){
		...
		countDownTIme: 10,
		stop: false,
		...
	}
	methods: {
		stopCountDown(){
			this.stop = !this.stop
			let cbTime = this.$refs.countDownModule.suspend(this.stop)
			let t = cbTime.split(':')
			!this.stop && (this.countDownTIme = Date.now() + (t[0] * 3600 + t[1] * 60 + Number(t[2])) * 1000)
		}
		...
	}
}
posted @ 2023-01-20 13:54  Z哎呀  阅读(1431)  评论(0)    收藏  举报