Skip to content

DatePicker 日期选择器

需要选择某一日期时使用

基础使用

使用 v-model 绑定日期值,默认为空字符串。

vue
<template>
  <ImDatePicker v-model="selectedDate" />
</template>

<script setup lang="ts">
import { ref, watch } from 'vue';
const selectedDate = ref('');
</script>

支持清除

设置 clearable 为 true,则可以清除已选择的日期。

vue
<template>
  <ImDatePicker clearable v-model="selectedDate" />
</template>

<script setup lang="ts">
import { ref, watch } from 'vue';
const selectedDate = ref('');
</script>

支持时间选择

设置 showTime 为 true,则可以同时选择日期和时间。

vue
<template>
  <ImDatePicker showTime format="YYYY-MM-DD HH:mm:ss" v-model="timeValue" />
</template>

<script setup lang="ts">
import { ref, watch } from 'vue';
const timeValue = ref('');
</script>

API

DatePickerProps

字段名类型描述
modelValuestring绑定的值
disabledboolean是否禁用,默认为false
readonlyboolean是否只读,默认为false
clearableboolean是否可清除内容,默认为false
placeholderstring占位符文本
formatstring日期格式
zIndexnumber设置组件的z-index值
placementImPlaceType弹出位置类型
showTimeboolean是否显示时间选择器,默认为false
disabledDate(date?: Date) => boolean禁用特定日期的函数

基于 MIT 协议发布