countDownCom.vue 1.71 KB
<template>
    <div class="count-down-com" v-if="time">
        <van-count-down class="count-down" :class="'style-' + sty" :time="time" @finish="finish">
            <template v-slot="timeData">
                <div class="container" v-if="timeData.days > 0">
                    <span class="block transparent">{{ timeData.days }}</span>
                    <span class="colon">天</span>
                </div>
                <div class="container">
                    <span class="block">{{ timeData.hours }}</span>
                    <span class="colon" v-if="sty == '2' || sty == '5'">时</span>
                    <span class="colon" v-else>:</span>
                    <span class="block">{{ timeData.minutes }}</span>
                    <span class="colon" v-if="sty == '2' || sty == '5'">分</span>
                    <span class="colon" v-else>:</span>
                    <span class="block">{{ timeData.seconds }}</span>
                    <span class="colon" v-if="sty == '2' || sty == '5'">秒</span>
                </div>
            </template>
        </van-count-down>
    </div>
</template>

<script>

    // 引入组件
	import Vue from 'vue';
	import { CountDown } from 'vant';

	Vue.use(CountDown);

    export default {
        name: "count-down-com",
        data: function () {
            return {
                
            }
        },
        props: ["time", "sty"],
        methods: {

            /**
             * 倒计时完成事件
             */
            finish() {
                this.$emit("finish");
            }
        }
    }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style rel="stylesheet/less" lang="less" scoped>
    @import './countDownCom';
</style>