diff --git a/src/packages/__VUE/calendar/doc.en-US.md b/src/packages/__VUE/calendar/doc.en-US.md index 24e740ae24..f9433e15a2 100644 --- a/src/packages/__VUE/calendar/doc.en-US.md +++ b/src/packages/__VUE/calendar/doc.en-US.md @@ -652,6 +652,7 @@ Through [ref](https://vuejs.org/guide/essentials/template-refs.html), you can ge | Name | Description | Arguments | |--------|------------------|---------------| | scrollToDate | Scroll to the month of the specified date:'2021-12-30' | `string` | +| initPosition `v4.0.1` | Initialize scroll position | | ## Theming ### CSS Variables diff --git a/src/packages/__VUE/calendar/doc.md b/src/packages/__VUE/calendar/doc.md index b4db2ddc69..7e45465f17 100644 --- a/src/packages/__VUE/calendar/doc.md +++ b/src/packages/__VUE/calendar/doc.md @@ -667,6 +667,7 @@ export default { | 方法名 | 说明 | 参数 | |----------------|-------------------|---------------| | scrollToDate | 滚动到指定日期所在月,如:'2021-12-30' | `string` | +| initPosition `v4.0.1` | 初始化滚动位置 | 无 | ## 主题定制 diff --git a/src/packages/__VUE/calendar/doc.taro.md b/src/packages/__VUE/calendar/doc.taro.md index 92d9e2e75e..4e036039ab 100644 --- a/src/packages/__VUE/calendar/doc.taro.md +++ b/src/packages/__VUE/calendar/doc.taro.md @@ -657,7 +657,7 @@ export default { | 方法名 | 说明 | 参数 | |--------|------------------|---------------| | scrollToDate | 滚动到指定日期所在月,如:'2021-12-30' | `string` | - +| initPosition `v4.0.1` | 初始化滚动位置 | 无 | ## 主题定制 ### 样式变量 diff --git a/src/packages/__VUE/calendar/index.taro.vue b/src/packages/__VUE/calendar/index.taro.vue index 0c1264fcfa..e92ee58742 100644 --- a/src/packages/__VUE/calendar/index.taro.vue +++ b/src/packages/__VUE/calendar/index.taro.vue @@ -187,8 +187,12 @@ export default create({ const scrollToDate = (date: string) => { calendarRef.value?.scrollToDate(date); }; + const initPosition = () => { + calendarRef.value?.initPosition(); + }; useExpose({ - scrollToDate + scrollToDate, + initPosition }); // methods const update = () => { diff --git a/src/packages/__VUE/calendar/index.vue b/src/packages/__VUE/calendar/index.vue index 6ccc27e041..a2ac5f88d4 100644 --- a/src/packages/__VUE/calendar/index.vue +++ b/src/packages/__VUE/calendar/index.vue @@ -185,8 +185,12 @@ export default create({ const scrollToDate = (date: string) => { calendarRef.value?.scrollToDate(date); }; + const initPosition = () => { + calendarRef.value?.initPosition(); + }; useExpose({ - scrollToDate + scrollToDate, + initPosition }); // methods const update = () => { diff --git a/src/packages/__VUE/calendaritem/index.taro.vue b/src/packages/__VUE/calendaritem/index.taro.vue index 46755ec3cc..c7bcba63e8 100644 --- a/src/packages/__VUE/calendaritem/index.taro.vue +++ b/src/packages/__VUE/calendaritem/index.taro.vue @@ -671,8 +671,12 @@ export default create({ } }); }; + const initPosition = () => { + state.scrollTop = Math.ceil(state.monthsData[state.currentIndex].cssScrollHeight); + }; useExpose({ - scrollToDate + scrollToDate, + initPosition }); const setDefaultRange = (monthsNum: number, current: number) => { let rangeArr: number[] = []; diff --git a/src/packages/__VUE/calendaritem/index.vue b/src/packages/__VUE/calendaritem/index.vue index 9a76d393cf..072faa7b0c 100644 --- a/src/packages/__VUE/calendaritem/index.vue +++ b/src/packages/__VUE/calendaritem/index.vue @@ -624,8 +624,14 @@ export default create({ } }); }; + const initPosition = () => { + if (months?.value) { + months.value.scrollTop = state.monthsData[state.currentIndex].cssScrollHeight; + } + }; useExpose({ - scrollToDate + scrollToDate, + initPosition }); // 设置当前可见月份 const setDefaultRange = (monthsNum: number, current: number) => { diff --git a/src/packages/__VUE/calendaritem/type.ts b/src/packages/__VUE/calendaritem/type.ts index 3805e665fc..21571b80a6 100644 --- a/src/packages/__VUE/calendaritem/type.ts +++ b/src/packages/__VUE/calendaritem/type.ts @@ -71,4 +71,5 @@ export interface MonthInfo { } export interface CalendarRef extends HTMLElement { scrollToDate: (date: string) => void; + initPosition: () => void; }