diff --git a/packages/vant-cli/site/desktop/App.vue b/packages/vant-cli/site/desktop/App.vue index e18e94467..8fb0bb4c2 100644 --- a/packages/vant-cli/site/desktop/App.vue +++ b/packages/vant-cli/site/desktop/App.vue @@ -83,6 +83,17 @@ export default { }, }, + mounted() { + if (this.$route.hash) { + this.$nextTick(() => { + const el = document.querySelector(this.$route.hash); + if (el) { + el.scrollIntoView(); + } + }); + } + }, + methods: { setTitleAndToogleSimulator() { let { title } = this.config; @@ -104,7 +115,11 @@ export default { document.title = title; - this.hasSimulator = !(config.site.hideSimulator || this.config.hideSimulator || (current && current.hideSimulator)); + this.hasSimulator = !( + config.site.hideSimulator || + this.config.hideSimulator || + (current && current.hideSimulator) + ); }, }, }; diff --git a/packages/vant-cli/site/desktop/utils.js b/packages/vant-cli/site/desktop/utils.js deleted file mode 100644 index ad9ed4ee9..000000000 --- a/packages/vant-cli/site/desktop/utils.js +++ /dev/null @@ -1,17 +0,0 @@ -export function scrollToAnchor(selector) { - let count = 0; - - const timer = setInterval(() => { - const el = document.querySelector('#' + selector); - if (el) { - el.scrollIntoView(); - clearInterval(timer); - } else { - count++; - - if (count > 10) { - clearInterval(timer); - } - } - }, 100); -}