Skip to content

CountDown 倒计时

基础用法

已结束
查看代码
vue
<template>
    <div style="display: flex; align-items: center; gap: 12px">
        <CountDown v-model="remain">
            <template #initial>已结束</template>
            <template #default="{ seconds }">剩余 {{ seconds }} 秒</template>
        </CountDown>
        <Button @click="remain = 10000">重新计时</Button>
    </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from "vue";
import { Button, CountDown } from "@a-drowned-fish/rox-v";

const remain = ref(0);
onMounted(() => {
    remain.value = 10000;
});
</script>

Props

参数说明类型默认值
modelValue (v-model)剩余时间(毫秒)numberundefined

插槽

插槽名子作用域说明
initialmodelValue0 / undefined / null 时展示
default{ seconds: number }倒计时进行中展示剩余秒数

说明

modelValue 被修改为大于 0 的值时自动开始倒计时;归零时会自动将 modelValue 置为 0

基于 MIT 协议开源