Skip to content
On this page

年月日(date)

mode 默认为 date ,通过 v-model 双向绑定数据,通过 ref 拿到 openclose 方法进行打开和关闭

vue
<template>
    <uvDatetimePicker
      round
      ref="uvdateRef"
      v-model="value"
      title="日期选择"
    />
</template>

<script setup>
const uvdateRef = ref(null)
const value = ref('')
</script>

年月(year-month)

mode 设置为 year-month 显示年月选择

vue
<template>
    <uvDatetimePicker
      round
      ref="uvdateRef1"
      v-model="value1"
      title="选择年月"
      mode="year-month"
    />
</template>

<script setup>
const uvdateRef1 = ref(null)
const value1 = ref('')
</script>

时间(time)

mode 设置为 time 显示时间选择

vue
<template>
    <uvDatetimePicker
      round
      ref="uvdateRef2"
      v-model="value2"
      title="选择时间"
      mode="time"
    />
</template>

<script setup>
const uvdateRef2 = ref(null)
const value2 = ref('')
</script>

完整时间(datetime)

mode 设置为 datetime 显示完整年月日时分

vue
<template>
    <uvDatetimePicker
      round
      ref="uvdateRef3"
      v-model="value3"
      title="选择日期时间"
      mode="datetime"
    />
</template>

<script setup>
const uvdateRef3 = ref(null)
const value3 = ref('')
</script>

格式化

通过传入 formatter 进行格式化

vue
<template>
    <uvDatetimePicker
      round
      ref="uvdateRef4"
      v-model="value4"
      title="日期选择"
      :formatter="formatter"
    />
</template>

<script setup>
const uvdateRef4 = ref(null)
const value4 = ref('')

const formatter = (type, option) => {
  if (type === 'year') {
    option.label += ''
  }
  if (type === 'month') {
    option.label += ''
  }
  if (type === 'day') {
    option.label += ''
  }
  return option
}

</script>

过滤选项

通过传入 filter 进行过滤数据

vue
<template>
    <uvDatetimePicker
      round
      ref="uvdateRef5"
      v-model="value5"
      title="日期选择"
      :filter="filter"
    />
</template>

<script setup>
const uvdateRef5 = ref(null)
const value5 = ref('')

const filter = (type, options) => {
  if (type === 'month') {
    return options.filter((option) => Number(option.value) % 6 === 0)
  }
  return options
}

</script>

props

属性含义类型默认值
modelValue双向绑定的值String-
minDate可选的最小时间Date十年前
maxDate可选的最大时间Date十年后
mode日期模式,datetime为完整日期 date为日期选择,time为时间选择,year-month为年月选择String'date'
formatter日期格式化Function(type, option) => option
filter日期数据过滤Function-
dateConnector日期连接字符串String'-'
timeConnector时间连接字符串String':'

events

事件名称含义参数
change选项改变时当前的子项
cancle点击取消时-
confim点击确定时-

css变量

css

Released under the MIT License.