import type { Ref } from 'vue' import { nextTick, ref } from 'vue' type ScrollElement = HTMLDivElement | null interface ScrollReturn { scrollRef: Ref scrollToBottom: () => Promise scrollToTop: () => Promise } export function useScroll(): ScrollReturn { const scrollRef = ref(null) const scrollToBottom = async () => { await nextTick() if (scrollRef.value) scrollRef.value.scrollTop = scrollRef.value.scrollHeight } const scrollToTop = async () => { await nextTick() if (scrollRef.value) scrollRef.value.scrollTop = 0 } return { scrollRef, scrollToBottom, scrollToTop, } }