Files
heroui-vue/apps/docs/demos/date-field-controlled.vue
2026-10-23 23:56:18 +08:00

39 lines
1.0 KiB
Vue
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import {
DateField,
DateFieldGroup,
DateFieldInput,
DateFieldSegment,
Label,
Description,
Button,
} from "@heroui-vue/components";
import { shallowRef } from "vue";
import {
today,
getLocalTimeZone,
type DateValue,
} from "@internationalized/date";
const value = shallowRef<DateValue | null>(null);
const todayDate = today(getLocalTimeZone());
</script>
<template>
<div class="flex flex-col gap-4">
<DateField v-model="value" class="w-[256px]" name="date">
<Label>日期</Label>
<DateFieldGroup>
<DateFieldInput v-slot="{ segment }">
<DateFieldSegment :segment="segment" />
</DateFieldInput>
</DateFieldGroup>
<Description>
当前值:{{ value ? value.toString() : "(空)" }}
</Description>
</DateField>
<div class="flex gap-2">
<Button variant="tertiary" @click="value = todayDate">设为今天</Button>
<Button variant="tertiary" @click="value = null">清空</Button>
</div>
</div>
</template>