mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(Calendar): add scrollToDate method (#7847)
This commit is contained in:
parent
9582cd2fae
commit
5ac6996e56
@ -314,9 +314,10 @@ Following props are supported when the type is multiple
|
|||||||
|
|
||||||
Use [ref](https://vuejs.org/v2/api/#ref) to get Calendar instance and call instance methods.
|
Use [ref](https://vuejs.org/v2/api/#ref) to get Calendar instance and call instance methods.
|
||||||
|
|
||||||
| Name | Description | Attribute | Return value |
|
| Name | Description | Attribute | Return value |
|
||||||
| ----- | ----------------------------------- | --------- | ------------ |
|
| --- | --- | --- | --- |
|
||||||
| reset | Reset selected date to default date | - | - |
|
| reset | Reset selected date to default date | - | - |
|
||||||
|
| scrollToDate `v2.12.2` | Scroll to date | _date: Date_ | - |
|
||||||
|
|
||||||
### Less Variables
|
### Less Variables
|
||||||
|
|
||||||
|
@ -320,9 +320,10 @@ export default {
|
|||||||
|
|
||||||
通过 ref 可以获取到 Calendar 实例并调用实例方法,详见[组件实例方法](#/zh-CN/advanced-usage#zu-jian-shi-li-fang-fa)。
|
通过 ref 可以获取到 Calendar 实例并调用实例方法,详见[组件实例方法](#/zh-CN/advanced-usage#zu-jian-shi-li-fang-fa)。
|
||||||
|
|
||||||
| 方法名 | 说明 | 参数 | 返回值 |
|
| 方法名 | 说明 | 参数 | 返回值 |
|
||||||
| ------ | ---------------------- | ---- | ------ |
|
| ---------------------- | ---------------------- | ------------ | ------ |
|
||||||
| reset | 重置选中的日期到默认值 | - | - |
|
| reset | 重置选中的日期到默认值 | - | - |
|
||||||
|
| scrollToDate `v2.12.2` | 滚动到某个日期 | _date: Date_ | - |
|
||||||
|
|
||||||
### 样式变量
|
### 样式变量
|
||||||
|
|
||||||
|
@ -192,17 +192,9 @@ export default createComponent({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// scroll to current month
|
// @exposed-api
|
||||||
scrollIntoView() {
|
scrollToDate(targetDate) {
|
||||||
raf(() => {
|
raf(() => {
|
||||||
const { currentDate } = this;
|
|
||||||
|
|
||||||
if (!currentDate) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const targetDate =
|
|
||||||
this.type === 'single' ? currentDate : currentDate[0];
|
|
||||||
const displayed = this.value || !this.poppable;
|
const displayed = this.value || !this.poppable;
|
||||||
|
|
||||||
/* istanbul ignore if */
|
/* istanbul ignore if */
|
||||||
@ -222,6 +214,17 @@ export default createComponent({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// scroll to current month
|
||||||
|
scrollIntoView() {
|
||||||
|
const { currentDate } = this;
|
||||||
|
|
||||||
|
if (currentDate) {
|
||||||
|
const targetDate =
|
||||||
|
this.type === 'single' ? currentDate : currentDate[0];
|
||||||
|
this.scrollToDate(targetDate);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
getInitialDate() {
|
getInitialDate() {
|
||||||
const { type, minDate, maxDate, defaultDate } = this;
|
const { type, minDate, maxDate, defaultDate } = this;
|
||||||
|
|
||||||
|
2
types/calendar.d.ts
vendored
2
types/calendar.d.ts
vendored
@ -2,4 +2,6 @@ import { VanComponent } from './component';
|
|||||||
|
|
||||||
export class Calendar extends VanComponent {
|
export class Calendar extends VanComponent {
|
||||||
reset(): void;
|
reset(): void;
|
||||||
|
|
||||||
|
scrollToDate(date: Date): void;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user