fix(Calendar): failed to render when default-date is null #7519

This commit is contained in:
chenjiahan
2020-11-11 21:01:34 +08:00
parent 2708e550c2
commit 704a9e3231
3 changed files with 16 additions and 15 deletions
+11 -10
View File
@@ -1,4 +1,4 @@
import { ref, watch, reactive, computed, onMounted, onActivated } from 'vue';
import { ref, watch, reactive, computed } from 'vue';
// Utils
import { pick, getScrollTop } from '../utils';
@@ -18,7 +18,7 @@ import {
} from './utils';
// Composition
import { raf, useRect } from '@vant/use';
import { raf, useRect, onMountedOrActivated } from '@vant/use';
import { useRefs } from '../composition/use-refs';
import { useExpose } from '../composition/use-expose';
@@ -270,18 +270,21 @@ export default createComponent({
// scroll to current month
const scrollIntoView = () => {
raf(() => {
const { currentDate } = state;
const displayed = props.show || !props.poppable;
if (!displayed) {
return;
}
onScroll();
const { currentDate } = state;
if (!currentDate) {
return;
}
const targetDate =
props.type === 'single' ? currentDate : currentDate[0];
const displayed = props.show || !props.poppable;
/* istanbul ignore if */
if (!targetDate || !displayed) {
if (!targetDate) {
return;
}
@@ -516,10 +519,8 @@ export default createComponent({
reset
);
onMounted(init);
onActivated(init);
useExpose({ reset });
onMountedOrActivated(init);
return () => {
if (props.poppable) {