<div ref="scrollDiv">

</div>
<script setup>
import { ref, reactive, onMounted, defineProps, nextTick } from 'vue'

const scrollDiv = ref(null)

onMounted(() => {
    //划动回到顶部
    nextTick(() => {
        let scrollElem = scrollDiv.value;
        scrollElem.scrollTo({ top: 0, behavior: 'smooth' });
    });
    // 滚动到底部
    nextTick(() => {
        let scrollElem = scrollDiv.value;
        scrollElem.scrollTo({ top: scrollElem.scrollHeight, behavior: 'smooth' });
    });

})
</script>

Logo

前往低代码交流专区

更多推荐