diff --git a/packages/vant-cli/site/desktop/components/Content.vue b/packages/vant-cli/site/desktop/components/Content.vue index ae2799cde..2fffc67dc 100644 --- a/packages/vant-cli/site/desktop/components/Content.vue +++ b/packages/vant-cli/site/desktop/components/Content.vue @@ -12,6 +12,11 @@ import { copyToClipboard } from '../../common'; export default { name: 'VanDocContent', + data() { + return { + iframeDocument: null, + }; + }, computed: { currentPage() { @@ -50,6 +55,19 @@ export default { name: this.$route.name, hash: '#' + target.id, }); + + this.syncMobilePos(target.id); + } + }, + + syncMobilePos(id) { + // Getting the document at this point is to ensure that the target has been fully rendered. + if (this.iframeDocument) { + const target = this.iframeDocument.getElementById(id); + target && target.scrollIntoView(true); + } else { + const iframe = document.querySelector('iframe'); + this.iframeDocument = iframe.contentWindow.document; } }, diff --git a/packages/vant-cli/site/mobile/components/DemoBlock.vue b/packages/vant-cli/site/mobile/components/DemoBlock.vue index c715695b9..3cd9d06ee 100644 --- a/packages/vant-cli/site/mobile/components/DemoBlock.vue +++ b/packages/vant-cli/site/mobile/components/DemoBlock.vue @@ -1,6 +1,8 @@