From 29a265c9052c396d9bbe29b20dfd1eaf71b1d56f Mon Sep 17 00:00:00 2001 From: zhifu Date: Tue, 17 Dec 2024 11:20:26 +0800 Subject: [PATCH 1/2] compiler: Fix rolling anomalies --- vdoing/components/RightMenu.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vdoing/components/RightMenu.vue b/vdoing/components/RightMenu.vue index 8146dfb0..c4d1371b 100644 --- a/vdoing/components/RightMenu.vue +++ b/vdoing/components/RightMenu.vue @@ -87,8 +87,6 @@ export default { $route() { this.headers = getNewHeaders(this.$page.headers); this.getHashText(); - // 滚动到指定位置 - this.scrollToHash(); }, }, methods: { @@ -100,6 +98,8 @@ export default { if (!this.hashText && this.headers) { this.hashText = this.headers[0]?.slug; } + // 滚动到指定位置 + this.scrollToHash(); }, scrollToHash() { const element = document.getElementById(`${this.hashText}-slug`); From 381f43e9d5d711f89ad877ce2c65bef2f8f879eb Mon Sep 17 00:00:00 2001 From: zhifu Date: Tue, 17 Dec 2024 15:12:29 +0800 Subject: [PATCH 2/2] compiler: nextTick run scrollToHash --- vdoing/components/RightMenu.vue | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vdoing/components/RightMenu.vue b/vdoing/components/RightMenu.vue index c4d1371b..5ad38f22 100644 --- a/vdoing/components/RightMenu.vue +++ b/vdoing/components/RightMenu.vue @@ -93,11 +93,13 @@ export default { getHeadersData() { this.headers = getNewHeaders(this.$page.headers); }, - getHashText() { + async getHashText() { this.hashText = decodeURIComponent(window.location.hash.slice(1)); if (!this.hashText && this.headers) { this.hashText = this.headers[0]?.slug; } + + await this.$nextTick(); // 滚动到指定位置 this.scrollToHash(); },