diff --git a/package.json b/package.json index 91c445d66..090aa6a57 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "dependencies": { "@babel/runtime": "7.x", "@vant/icons": "1.4.0", - "@vant/use": "^0.0.9", + "@vant/use": "^0.1.0", "vue-lazyload": "1.2.3" }, "peerDependencies": { diff --git a/src/calendar/index.js b/src/calendar/index.js index c4c666913..2094f8315 100644 --- a/src/calendar/index.js +++ b/src/calendar/index.js @@ -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) { diff --git a/yarn.lock b/yarn.lock index 124aaf5ba..d53c8b6a2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1957,10 +1957,10 @@ resolved "https://registry.yarnpkg.com/@vant/touch-emulator/-/touch-emulator-1.2.0.tgz#486300b23e57db9ce9231a04e0a0c621c68692d8" integrity sha512-sJ97zU85zOq51qoi7+CpBEcOyH3CitjP1KC7/GQwqaurUJni+EP7/F9n0HMnAh8GXMjgtgDBNJ5z48x+coNKYQ== -"@vant/use@^0.0.9": - version "0.0.9" - resolved "https://registry.npmjs.org/@vant/use/-/use-0.0.9.tgz#938b41e8dd682f063450f45699111ab30dd279c1" - integrity sha512-P+/q3MqFCmoNStQU8qpPxDNtBLy9Q82xx05APm7ZqEhoJLPynK1u0giC1JeEvFoSTEJ3y4XxN+R7YqmpXnf/7Q== +"@vant/use@^0.1.0": + version "0.1.0" + resolved "https://registry.npm.taobao.org/@vant/use/download/@vant/use-0.1.0.tgz?cache=0&sync_timestamp=1605099108765&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40vant%2Fuse%2Fdownload%2F%40vant%2Fuse-0.1.0.tgz#7d2020aa7e5ab92d57dea46cb24dd9013c7eacee" + integrity sha1-fSAgqn5auS1X3qRssk3ZATx+rO4= "@vue/babel-helper-vue-transform-on@^1.0.0-rc.2": version "1.0.0-rc.2"