diff --git a/src/calendar/index.js b/src/calendar/index.js index 5fc0c1ec4..6f6b7052d 100644 --- a/src/calendar/index.js +++ b/src/calendar/index.js @@ -266,28 +266,33 @@ export default createComponent({ let height = 0; let currentMonth; - let visibleIndex; + const visibleRange = [-1, -1]; for (let i = 0; i < months.length; i++) { const visible = height <= bottom && height + heights[i] >= top; - if (visible && !currentMonth) { - visibleIndex = i; - currentMonth = months[i]; - } + if (visible) { + visibleRange[1] = i; - if (!months[i].visible && visible) { - this.$emit('month-show', { - date: months[i].date, - title: months[i].title, - }); + if (!currentMonth) { + currentMonth = months[i]; + visibleRange[0] = i; + } + + if (!months[i].visible) { + this.$emit('month-show', { + date: months[i].date, + title: months[i].title, + }); + } } height += heights[i]; } months.forEach((month, index) => { - month.visible = index >= visibleIndex - 1 && index <= visibleIndex + 1; + month.visible = + index >= visibleRange[0] - 1 && index <= visibleRange[1] + 1; }); /* istanbul ignore else */ diff --git a/src/calendar/test/__snapshots__/demo.spec.js.snap b/src/calendar/test/__snapshots__/demo.spec.js.snap index 74018afa8..b0a56dda3 100644 --- a/src/calendar/test/__snapshots__/demo.spec.js.snap +++ b/src/calendar/test/__snapshots__/demo.spec.js.snap @@ -139,7 +139,40 @@ exports[`renders demo correctly 1`] = `