Skip to content

Commit 30aa296

Browse files
authored
docs(site): fix demo anchor error (#2286)
1 parent 78ce3ad commit 30aa296

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

examples/sites/src/views/components/components.vue

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ export default defineComponent({
459459
})
460460
}
461461
}
462-
}, 600)
462+
}, 0)
463463
}
464464
465465
// 在singleDemo情况时,才需要滚动示例区域到顶
@@ -565,7 +565,12 @@ export default defineComponent({
565565
}
566566
567567
// F5刷新加载时,跳到当前示例
568-
scrollByHash(hash)
568+
// 应当在所有demo渲染完毕后在滚动,否则滚动完位置后,demo渲染会使滚动位置错位
569+
setTimeout(() => {
570+
nextTick(() => {
571+
scrollByHash(hash)
572+
})
573+
}, 0)
569574
})
570575
.finally(() => {
571576
// 获取组件贡献者
@@ -652,12 +657,14 @@ export default defineComponent({
652657
653658
router.push(data.link)
654659
} else if (apiModeState.demoMode === 'default' && data.link.startsWith('#')) {
660+
e.preventDefault()
655661
// 多示例模式,自动会切到相应的位置。只需要记录singleDemo就好了
656662
const hash = data.link.slice(1)
657663
state.currDemoId = hash
658664
state.singleDemo = state.currJson.demos.find((d) => d.demoId === hash)
659665
660-
e.preventDefault()
666+
router.push(data.link)
667+
scrollByHash(hash)
661668
}
662669
}
663670
}

0 commit comments

Comments
 (0)