Skip to content

Calendar 日历选择

用于日期选择、入住离店时间段范围选择与多日期批量选择的底部弹窗日历控件,支持 single (单选)、range (范围选择) 与 multiple (多选)。


代码示例

1. 基础单选模式 (Single Date)

vue
<template>
  <mu-button type="primary" block @click="show = true">
    {{ date ? `已选: ${date}` : '选择预约日期' }}
  </mu-button>

  <mu-calendar v-model:show="show" v-model="date" title="选择预约日期" @confirm="onConfirm" />
</template>

<script setup>
import { ref } from 'vue'

const show = ref(false)
const date = ref('2026-07-24')

function onConfirm(val) {
  console.log('确认日期:', val)
}
</script>

2. 酒店入住区间选择 (Range Mode)

设置 type="range" 支持一次性选择起始与结束入住日期。

vue
<template>
  <mu-calendar
    v-model:show="showRange"
    v-model="dateRange"
    type="range"
    title="选择入住与离店日期"
  />
</template>

<script setup>
import { ref } from 'vue'

const showRange = ref(false)
const dateRange = ref(['2026-07-24', '2026-07-28'])
</script>

API 属性说明 (Props)

参数名说明类型可选值默认值
v-model:show / show控制日历弹窗显隐Booleantrue | falsefalse
v-model / modelValue选中的日期 (单选为 String,范围选/多选为 Array)String | Array-''
defaultDate默认选中日期String | Array-''
title弹窗顶部栏标题String-'选择日期'
type选择模式Stringsingle (单选) | range (范围选) | multiple (多选)'single'
minDate最小可选日期 (格式 'YYYY-MM-DD')String-'' (默认今天)
maxDate最大可选日期 (格式 'YYYY-MM-DD')String-'' (默认 6 个月后)
maxMonth允许向上滚动的月份跨度限制Number-6
showConfirm是否显示底部确认按钮Booleantrue | falsetrue
confirmText确认按钮文案String-'确定'

事件说明 (Events)

事件名说明回调参数
update:showv-model:show 双向绑定更新(show: boolean)
update:modelValuev-model 双向绑定更新(value: String | Array)
confirm点击确认按钮时触发(value: String | Array)
change选中日期发生改变时触发(value: String | Array)
close弹窗关闭收起时触发-

实例方法 (Expose Methods)

方法名说明
open()唤醒并打开日历
close()关闭日历弹窗

基于 MIT 协议开源发行

H5 模拟器 (calendar)☀️🔄