export const usePageScroll = () => {
const scrollTop = ref(0);
onPageScroll((e) => {
scrollTop.value = e.scrollTop;
});
return { scrollTop };
};
<template>
<view></view>
</template>
<script setup lang="ts">
import { watchEffect } from 'vue';
import { usePageScroll } from '@/hooks/useScroll';
const {scrollTop} = useScroll()
watchEffect(() => {
console.log(scrollTop);
});
</script>
随便起的名字 (作者)
好的,了解了。
2023-10-26 14:14