Date Time Picker
DateTimePicker component for selecting date and time, with support for clearing, disabling, and error indication.
Date Time Picker
DateTimePicker component for selecting date and time, with support for clearing, disabling, and error indication.
Usage Examples
<template>
<div>
<label class="block text-sm font-medium mb-1">{{ t('themeDocs.dateTimePicker.selectDateTime') }}</label>
<DateTimePicker v-model="dateValue" />
<div class="mt-4">
<p>{{ t('themeDocs.dateTimePicker.selectedValue') }}:
<span v-if="dateValue">{{ dateValue }}</span>
<span v-else class="text-gray-500">{{ t('themeDocs.dateTimePicker.noDateSelected') }}</span>
</p>
</div>
</div>
</template>
<script setup>
import { ref } from 'vue'
import DateTimePicker from '~/components/theme/DateTimePicker.vue'
const dateValue = ref(new Date().toISOString())
</script>
Clearable Example
<template>
<div>
<label class="block text-sm font-medium mb-1">{{ t('themeDocs.dateTimePicker.clearableTitle') }}</label>
<DateTimePicker v-model="dateValue" :clearable="true" />
<label class="block text-sm font-medium mt-4 mb-1">{{ t('themeDocs.dateTimePicker.nonClearableTitle') }}</label>
<DateTimePicker v-model="dateValue2" :clearable="false" />
<div class="mt-4">
<p>{{ t('themeDocs.dateTimePicker.clearableValue') }}:
<span v-if="dateValue">{{ dateValue }}</span>
<span v-else class="text-gray-500">{{ t('themeDocs.dateTimePicker.noDateSelected') }}</span>
</p>
<p>{{ t('themeDocs.dateTimePicker.nonClearableValue') }}:
<span v-if="dateValue2">{{ dateValue2 }}</span>
<span v-else class="text-gray-500">{{ t('themeDocs.dateTimePicker.noDateSelected') }}</span>
</p>
</div>
</div>
</template>
<script setup>
import { ref } from 'vue'
import DateTimePicker from '~/components/theme/DateTimePicker.vue'
const dateValue = ref(new Date().toISOString())
const dateValue2 = ref(new Date().toISOString())
</script>
Disabled Example
<template>
<div>
<label class="block text-sm font-medium mb-1">{{ t('themeDocs.dateTimePicker.disabledTitle') }}</label>
<DateTimePicker v-model="dateValue" :disabled="true" />
<div class="mt-4">
<p>{{ t('themeDocs.dateTimePicker.disabledValue') }}:
<span v-if="dateValue">{{ dateValue }}</span>
<span v-else class="text-gray-500">{{ t('themeDocs.dateTimePicker.noDateSelected') }}</span>
</p>
</div>
</div>
</template>
<script setup>
import { ref } from 'vue'
import DateTimePicker from '~/components/theme/DateTimePicker.vue'
const dateValue = ref(new Date().toISOString())
</script>
Error Example
<template>
<div>
<label class="block text-sm font-medium mb-1">{{ t('themeDocs.dateTimePicker.errorTitle') }}</label>
<DateTimePicker
v-model="dateValue"
:error="hasError"
error-message="请选择有效的日期和时间"
/>
<label class="block text-sm font-medium mt-4 mb-1">{{ t('themeDocs.dateTimePicker.customErrorTitle') }}</label>
<DateTimePicker
v-model="dateValue2"
error="此日期不符合业务规则要求"
/>
<div class="flex items-center gap-4 mt-4">
<Button @click="toggleError">
{{ hasError ? '清除错误' : '设置错误状态' }}
</Button>
</div>
</div>
</template>
<script setup>
import { ref } from 'vue'
import DateTimePicker from '~/components/theme/DateTimePicker.vue'
import Button from '~/components/theme/Button.vue'
const dateValue = ref(new Date().toISOString())
const dateValue2 = ref(new Date().toISOString())
const hasError = ref(false)
const toggleError = () => {
hasError.value = !hasError.value
}
</script>
Range Example
<template>
<div>
<label class="block text-sm font-medium mb-1">{{ t('themeDocs.dateTimePicker.dateRangeTitle') }}</label>
<p class="text-sm text-gray-500 mb-2">{{ t('themeDocs.dateTimePicker.dateRangeDescription') }}</p>
<DateTimePicker
v-model="dateValue"
:min="minDate"
:max="maxDate"
/>
<div class="mt-4">
<p>{{ t('themeDocs.dateTimePicker.minDate') }}: {{ minDateFormatted }}</p>
<p>{{ t('themeDocs.dateTimePicker.maxDate') }}: {{ maxDateFormatted }}</p>
<p>{{ t('themeDocs.dateTimePicker.selectedValue') }}:
<span v-if="dateValue">{{ dateValue }}</span>
<span v-else class="text-gray-500">{{ t('themeDocs.dateTimePicker.noDateSelected') }}</span>
</p>
</div>
</div>
</template>
<script setup>
import { ref, computed } from 'vue'
import DateTimePicker from '~/components/theme/DateTimePicker.vue'
const today = new Date()
const minDate = new Date(today)
minDate.setDate(today.getDate() - 7)
const maxDate = new Date(today)
maxDate.setDate(today.getDate() + 7)
const dateValue = ref(today.toISOString())
const formatDate = (date) => {
return new Date(date).toLocaleString()
}
const minDateFormatted = computed(() => formatDate(minDate))
const maxDateFormatted = computed(() => formatDate(maxDate))
</script>
Properties
Property | Basic component module for translation keys shared across all component documentation pages | Type | Default |
---|
modelValue | Value of the component, can be a Date object, ISO date string, or null | Date, String, null | null |
clearable | Whether to show a clear button, allowing users to empty the selected value | Boolean | true |
disabled | Whether the component is disabled, preventing user interaction | Boolean | false |
error | Whether to show an error state, can be a boolean or an error message string | Boolean, String | false |
errorMessage | Error message to display when error is true | String | Please enter a valid date and time |
format | Output format for the date and time, defaults to ISO format | String | ISO |
min | Minimum selectable date, dates before this will be disabled | Date, String | null |
max | Maximum selectable date, dates after this will be disabled | Date, String | null |
Events
Event | Basic component module for translation keys shared across all component documentation pages | Parameters |
---|
update:modelValue | Emitted when the component value changes | value: String, null Updated date time value, as ISO string or null |
change | Emitted when the user changes the date | date: Date, null Updated date time, as Date object or null |
Design Empowers, Innovation Unlimited