diff --git a/src/calendar/README.md b/src/calendar/README.md index 15faa7689..6666f9039 100644 --- a/src/calendar/README.md +++ b/src/calendar/README.md @@ -336,7 +336,7 @@ Use [ref](https://v3.vuejs.org/guide/component-template-refs.html) to get Calend | Name | Description | Attribute | Return value | | --- | --- | --- | --- | -| reset | Reset selected date to default date | - | - | +| reset | Reset selected date, will reset to default date when no params passed | _date?: Date \| Date[]_ | - | | scrollToDate | Scroll to date | _date: Date_ | - | ### Less Variables diff --git a/src/calendar/README.zh-CN.md b/src/calendar/README.zh-CN.md index 5fb6e2437..d4710d487 100644 --- a/src/calendar/README.zh-CN.md +++ b/src/calendar/README.zh-CN.md @@ -340,10 +340,10 @@ export default { 通过 ref 可以获取到 Calendar 实例并调用实例方法,详见[组件实例方法](#/zh-CN/advanced-usage#zu-jian-shi-li-fang-fa)。 -| 方法名 | 说明 | 参数 | 返回值 | -| ------------ | ---------------------- | ------------ | ------ | -| reset | 重置选中的日期到默认值 | - | - | -| scrollToDate | 滚动到某个日期 | _date: Date_ | - | +| 方法名 | 说明 | 参数 | 返回值 | +| --- | --- | --- | --- | +| reset | 将选中的日期重置到指定日期,未传参时会重置到默认日期 | _date?: Date \| Date[]_ | - | +| scrollToDate | 滚动到某个日期 | _date: Date_ | - | ### 样式变量 diff --git a/src/calendar/index.js b/src/calendar/index.js index 1929690ac..60c477ff5 100644 --- a/src/calendar/index.js +++ b/src/calendar/index.js @@ -311,8 +311,8 @@ export default createComponent({ }); }; - const reset = () => { - state.currentDate = getInitialDate(state.currentDate); + const reset = (date = getInitialDate(state.currentDate)) => { + state.currentDate = date; scrollIntoView(); }; diff --git a/types/calendar.d.ts b/types/calendar.d.ts index bc815f8d0..f516e2f06 100644 --- a/types/calendar.d.ts +++ b/types/calendar.d.ts @@ -1,7 +1,7 @@ import { VanComponent } from './component'; export class Calendar extends VanComponent { - reset(): void; + reset(date?: Date | Date[]): void; scrollToDate(date: Date): void; }