uniapp倒计时组件 传递时间就可以了

<template>
    <view v-if="show">
        <view class="down-time-char">
            <text style="margin-right: 15rpx;">仅剩</text>
            <uni-countdown color="#f52f46" :show-day="false" :hour="hour" :minute="minute" :second="second"></uni-countdown>
        </view>
    </view>
</template>

<script>
import moment from "moment"
export default {
    name: "down-for-time",
    props: ["createTime"],
    data() {
        return {
            show: false,
            hour: 0,
            minute: 0,
            second: 0
        }
    },
    mounted() {
        if(moment(this.createTime).add(30, "minutes").isAfter(moment())) {
            this.show = true
            this.timer()
        }
    },
    destroyed() {
        
    },
    methods: {
        timer() {
                let dTime = moment(this.createTime).add(30, "minutes").diff(moment())
                console.log(moment.duration(dTime),'ddd')
                const duration = moment.duration(dTime)
                this.hour = duration.hours()
                this.minute = duration.minutes()
                this.seconds = duration.seconds()
                // this.downTime = "00:" + duration.minutes() + ":" + duration.seconds()
        },
    }
}
</script>

<style lang="scss" scoped>
.down-time-char {
    display: flex;
    align-items: center;
    font-size: 28rpx;
    font-family: PingFang SC, PingFang SC-Bold;
    font-weight: 700;
    text-align: center;
    color: #f52f46;
    margin-right: 49rpx;
}
</style>

使用:<DownTime :createTime="item.createTime"></DownTime>//传递时间就可以了

    export default {
        components: {
            DownTime
        },

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值