Files
yshop-pro-uniapp/hooks/useScroll.js

28 lines
480 B
JavaScript
Raw Normal View History

2023-11-17 20:55:32 +08:00
import { onLoad, onPageScroll } from "@dcloudio/uni-app";
2023-11-15 19:59:37 +08:00
import { onBeforeUnmount, ref } from "vue";
export function useScroll(){
2023-11-17 20:55:32 +08:00
const scrollTop = ref(0)
2023-11-15 19:59:37 +08:00
onPageScroll((e)=>{
scrollTop.value = e.scrollTop
})
2023-11-17 20:55:32 +08:00
2023-11-15 19:59:37 +08:00
onBeforeUnmount(()=>{
scrollTop.value = 0
})
2023-11-17 20:55:32 +08:00
function scrollToTop(){
uni.pageScrollTo({
scrollTop: 0,
duration: 500
})
}
2023-11-15 19:59:37 +08:00
return {
2023-11-17 20:55:32 +08:00
scrollTop,
scrollToTop
2023-11-15 19:59:37 +08:00
}
2023-11-17 20:55:32 +08:00
2023-11-15 19:59:37 +08:00
}