diff --git a/packages/calendar/README.md b/packages/calendar/README.md index 05349ae5..de21ae24 100644 --- a/packages/calendar/README.md +++ b/packages/calendar/README.md @@ -274,7 +274,7 @@ Page({ | color | 主题色,对底部按钮和选中日期生效 | _string_ | `#ee0a24` | | min-date | 可选择的最小日期 | _timestamp_ | 当前日期 | | max-date | 可选择的最大日期 | _timestamp_ | 当前日期的六个月后 | -| default-date | 默认选中的日期,`type`为`multiple`或`range`时为数组 | _timestamp \| timestamp[]_ | 今天 | +| default-date `v1.10.21` | 默认选中的日期,`type`为`multiple`或`range`时为数组,传入 `null` 表示默认不选择| _timestamp \| timestamp[] \| null_ | 今天 | | row-height | 日期行高 | _number \| string_ | `64` | | formatter | 日期格式化函数 | _(day: Day) => Day_ | - | | poppable | 是否以弹层的形式展示日历 | _boolean_ | `true` | diff --git a/packages/calendar/index.ts b/packages/calendar/index.ts index ab3e16de..4c897360 100644 --- a/packages/calendar/index.ts +++ b/packages/calendar/index.ts @@ -63,6 +63,7 @@ VantComponent({ }, defaultDate: { type: null, + value: getToday().getTime(), observer(val) { this.setData({ currentDate: val }); this.scrollIntoView(); @@ -202,6 +203,8 @@ VantComponent({ getInitialDate(defaultDate: number | number[] | null = null) { const { type, minDate, maxDate, allowSameDay } = this.data; + if (!defaultDate) return []; + const now = getToday().getTime(); if (type === 'range') { @@ -245,6 +248,7 @@ VantComponent({ requestAnimationFrame(() => { const { currentDate, type, show, poppable, minDate, maxDate } = this.data; + if (!currentDate) return; // @ts-ignore const targetDate = type === 'single' ? currentDate : currentDate[0]; const displayed = show || !poppable;