Skip to content

Commit

Permalink
fix(index-bar): init scroller when start to scroll for nuxt (#1460)
Browse files Browse the repository at this point in the history
  • Loading branch information
chouchouji authored Feb 3, 2024
1 parent 60e0e07 commit 9b9ad8c
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 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(setupScroller)
onBeforeUnmount(removeScrollerListener)
Expand Down Expand Up @@ -170,17 +167,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
}
scroller.removeEventListener('scroll', handleScroll)
}
// expose
Expand Down

0 comments on commit 9b9ad8c

Please sign in to comment.