Skip to content

Commit

Permalink
fix(index-bar): init scroller when start to scroll for nuxt
Browse files Browse the repository at this point in the history
  • Loading branch information
chouchouji committed Feb 3, 2024
1 parent e61d046 commit 5baaefa
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions packages/varlet-ui/src/index-bar/IndexBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ export default defineComponent({
}
)
onSmartMounted(async () => {
await setScroller()
addScrollerListener()
})
onSmartMounted(handleScroll)
onBeforeUnmount(removeScrollerListener)
Expand Down Expand Up @@ -116,6 +113,10 @@ export default defineComponent({
}
function handleScroll() {
if (!scroller) {
setupScroller()
}
const scrollTop = getScrollTop(scroller!)
const scrollHeight = scroller === window ? document.body.scrollHeight : (scroller as HTMLElement).scrollHeight
const offsetTop = getOffsetTop()
Expand Down Expand Up @@ -170,17 +171,17 @@ export default defineComponent({
clickedName.value = ''
}
async function setScroller() {
await doubleRaf()
function setupScroller() {
scroller = getParentScroller(barEl.value as HTMLElement)
}
function addScrollerListener() {
scroller!.addEventListener('scroll', handleScroll)
scroller.addEventListener('scroll', handleScroll)
}
function removeScrollerListener() {
scroller!.removeEventListener('scroll', handleScroll)
if (!scroller) {
return

Check warning on line 181 in packages/varlet-ui/src/index-bar/IndexBar.vue

View check run for this annotation

Codecov / codecov/patch

packages/varlet-ui/src/index-bar/IndexBar.vue#L181

Added line #L181 was not covered by tests
}
scroller.removeEventListener('scroll', handleScroll)
}
// expose
Expand Down

0 comments on commit 5baaefa

Please sign in to comment.