代码提交
This commit is contained in:
@ -1,15 +1,27 @@
|
||||
import { onPageScroll } from "@dcloudio/uni-app";
|
||||
import { onLoad, onPageScroll } from "@dcloudio/uni-app";
|
||||
import { onBeforeUnmount, ref } from "vue";
|
||||
const scrollTop = ref(0)
|
||||
|
||||
export function useScroll(){
|
||||
const scrollTop = ref(0)
|
||||
|
||||
onPageScroll((e)=>{
|
||||
scrollTop.value = e.scrollTop
|
||||
})
|
||||
|
||||
onBeforeUnmount(()=>{
|
||||
scrollTop.value = 0
|
||||
})
|
||||
return {
|
||||
scrollTop
|
||||
|
||||
function scrollToTop(){
|
||||
uni.pageScrollTo({
|
||||
scrollTop: 0,
|
||||
duration: 500
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
scrollTop,
|
||||
scrollToTop
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user