Skip to content

Commit

Permalink
fix: 🐛 修复LockScroll后切换页面无法滚动 (#478)
Browse files Browse the repository at this point in the history
Closes: #473
  • Loading branch information
Moonofweisheng authored Aug 1, 2024
1 parent 84826f8 commit 197d61a
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ref, watch } from 'vue'
import { onBeforeUnmount, onDeactivated, ref, watch } from 'vue'

function useLockScroll(shouldLock: () => boolean) {
const scrollLockCount = ref(0)
Expand All @@ -19,10 +19,17 @@ function useLockScroll(shouldLock: () => boolean) {
}
}

const destroy = () => {
shouldLock() && unlock()
}

watch(shouldLock, (value) => {
value ? lock() : unlock()
})

onDeactivated(destroy)
onBeforeUnmount(destroy)

return {
lock,
unlock
Expand Down

0 comments on commit 197d61a

Please sign in to comment.