refactor: fixed the problem that the scroll component could not remember the height

This commit is contained in:
zyronon 2024-05-03 17:03:46 +08:00
parent d2b532a760
commit eff3277513
2 changed files with 17 additions and 13 deletions

View File

@ -1,13 +0,0 @@
import { onActivated, onDeactivated } from 'vue'
export function useBase() {
const mainScroll = $ref()
const mainScrollTop = $ref(0)
onActivated(() => {
console.log('onActivated')
})
onDeactivated(() => {
console.log('onDeactivated')
})
}

View File

@ -0,0 +1,17 @@
import { onActivated, onDeactivated, ref } from 'vue'
export function useScroll() {
const mainScroll = ref()
let mainScrollTop = $ref(0)
onActivated(() => {
if (mainScroll.value && mainScroll.value.wrapper) {
mainScroll.value.wrapper.scrollTop = mainScrollTop
}
})
onDeactivated(() => {
if (mainScroll.value && mainScroll.value.wrapper) {
mainScrollTop = mainScroll.value.wrapper.scrollTop
}
})
return mainScroll
}