Skip to content
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(site): fix demo anchor error #2286

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions examples/sites/src/views/components/components.vue
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ export default defineComponent({
})
}
}
}, 600)
}, 0)
}

// 在singleDemo情况时,才需要滚动示例区域到顶
Expand Down Expand Up @@ -565,7 +565,12 @@ export default defineComponent({
}

// F5刷新加载时,跳到当前示例
scrollByHash(hash)
// 应当在所有demo渲染完毕后在滚动,否则滚动完位置后,demo渲染会使滚动位置错位
setTimeout(() => {
nextTick(() => {
scrollByHash(hash)
})
}, 0)
})
.finally(() => {
// 获取组件贡献者
Expand Down Expand Up @@ -652,12 +657,14 @@ export default defineComponent({

router.push(data.link)
} else if (apiModeState.demoMode === 'default' && data.link.startsWith('#')) {
e.preventDefault()
// 多示例模式,自动会切到相应的位置。只需要记录singleDemo就好了
const hash = data.link.slice(1)
state.currDemoId = hash
state.singleDemo = state.currJson.demos.find((d) => d.demoId === hash)

e.preventDefault()
router.push(data.link)
scrollByHash(hash)
}
}
}
Expand Down
Loading