Last active
November 21, 2023 10:52
-
-
Save monsat/e9e0589fd3cc3c749e38e09392b921f5 to your computer and use it in GitHub Desktop.
The TimeLimit component is a versatile Vue.js component designed to display content only within a specified time range. This component is particularly useful in scenarios where you need to show or hide elements based on time constraints, such as limited-time offers, event announcements, or scheduled content.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script setup lang="ts"> | |
const props = defineProps<{ | |
startAt?: Date | number | |
endAt?: Date | number | |
now?: Date | number | |
}>() | |
const isBetween = computed(() => { | |
const now = props.now ?? Date.now() | |
const startAt = props.startAt ?? now | |
const endAt = props.endAt ?? now | |
return now >= startAt && now <= endAt | |
}) | |
</script> | |
<template> | |
<slot v-if="isBetween"></slot> | |
</template> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment