<template> <span v-if="this.localSecNum > 0 " style="margin-left:30px;"> 注意:<span style="color: #f5222d;margin: 0 12px;">{{ this.localSecNum > 0 ? getRemainTime() : '' }}</span>后所有任务将被释放,请尽快审核! </span> </template> <script> export default { name: 'CountDown', props: { secNum: { type: Number, default: 0 } }, data () { return { localSecNum: 0, timer: null } }, watch: { localSecNum (newv, oldv) {} }, created () { console.log('new create countdown time ..', this.secNum) }, mounted () { this.localSecNum = this.secNum if (this.localSecNum > 0) { this.beginCount = true // 设置定时器 this.timer = setInterval(() => { this.localSecNum-- if (this.localSecNum == 0) { this.timer = null this.$emit('endCount') } }, 1000) } else { this.beginCount = false } }, activated () { }, methods: { getRemainTime () { const time = this.localSecNum // var d = parseInt(time/3600/24) var h = parseInt(time / (60 * 60)) % 24 var m = parseInt(time / 60) % 60 var s = parseInt(time % 60) return h + ' 小时 ' + m + ' 分 ' + s + '秒' } } } </script>
标签:60,secNum,倒计时,parseInt,time,var,localSecNum From: https://www.cnblogs.com/dhjy123/p/17577001.html