-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: fix demo anchor position not correct #2391
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,6 +107,7 @@ | |
:demo="demo" | ||
:curr-demo-id="currDemoId" | ||
class="mb32" | ||
@mounted="demoMounted" | ||
/> | ||
</div> | ||
<div v-else> | ||
|
@@ -224,6 +225,7 @@ | |
<div class="cmp-page-anchor catalog" v-if="currAnchorLinks.length"> | ||
<tiny-anchor | ||
id="anchor" | ||
:offset-top="156" | ||
:links="currAnchorLinks" | ||
:key="anchorRefreshKey" | ||
:is-affix="anchorAffix" | ||
|
@@ -338,6 +340,26 @@ export default defineComponent({ | |
const { apiModeState } = useApiMode() | ||
const { templateModeState, staticPath, optionsList } = useTemplateMode() | ||
|
||
let finishNum = 0 | ||
let isAllMounted = false | ||
let demoMountedResolve | ||
const demoMounted = () => { | ||
finishNum++ | ||
if (finishNum === state.currJson.demos.length) { | ||
isAllMounted = true | ||
demoMountedResolve(true) | ||
} | ||
} | ||
|
||
const allDemoMounted = async () => { | ||
if (isAllMounted) { | ||
return isAllMounted | ||
} | ||
return new Promise((resolve) => { | ||
demoMountedResolve = resolve | ||
}) | ||
} | ||
Comment on lines
+343
to
+361
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure mounting state variables are reset appropriately Variables Apply this diff to reset the variables at the beginning of the const loadPage = debounce(templateModeState.isSaas ? 100 : 0, false, () => {
+ finishNum = 0
+ isAllMounted = false
+ demoMountedResolve = null
const lang = getWord('cn', 'en')
state.cmpId = router.currentRoute.value.params.cmpId
|
||
|
||
const getApiAnchorLinks = () => { | ||
if (!state.currJson.apis?.length) { | ||
return [] | ||
|
@@ -569,11 +591,9 @@ export default defineComponent({ | |
|
||
// F5刷新加载时,跳到当前示例 | ||
// 应当在所有demo渲染完毕后在滚动,否则滚动完位置后,demo渲染会使滚动位置错位 | ||
setTimeout(() => { | ||
nextTick(() => { | ||
scrollByHash(hash) | ||
}) | ||
}, 0) | ||
return allDemoMounted().then(() => { | ||
scrollByHash(hash) | ||
}) | ||
}) | ||
.finally(() => { | ||
// 获取组件贡献者 | ||
|
@@ -616,6 +636,7 @@ export default defineComponent({ | |
} | ||
|
||
const fn = { | ||
demoMounted, | ||
copyText: (text) => { | ||
navigator.clipboard.writeText(text) | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add safety checks and consider type constants
While the logic is sound, consider these improvements for robustness:
Here's a suggested improvement:
📝 Committable suggestion