diff --git a/packages/vant/src/calendar/Calendar.tsx b/packages/vant/src/calendar/Calendar.tsx index 8d9b12f7c..26a76e1f5 100644 --- a/packages/vant/src/calendar/Calendar.tsx +++ b/packages/vant/src/calendar/Calendar.tsx @@ -176,8 +176,8 @@ export default defineComponent({ const bodyRef = ref(); - const subtitle = ref<{ text: string; date?: Date }>({ - text: '', + const subtitle = ref<{ textFn: () => string; date?: Date }>({ + textFn: () => '', date: undefined, }); const currentDate = ref(getInitialDate()); @@ -272,7 +272,7 @@ export default defineComponent({ /* istanbul ignore else */ if (currentMonth) { subtitle.value = { - text: currentMonth.getTitle(), + textFn: currentMonth.getTitle, date: currentMonth.date, }; } @@ -529,24 +529,29 @@ export default defineComponent({ ); - const renderCalendar = () => ( -
- emit('clickSubtitle', event)} - /> -
- {months.value.map(renderMonth)} + const renderCalendar = () => { + const subTitle = subtitle.value.textFn(); + return ( +
+ + emit('clickSubtitle', event) + } + /> +
+ {months.value.map(renderMonth)} +
+ {renderFooter()}
- {renderFooter()} -
- ); + ); + }; watch(() => props.show, init); watch(