Vue3 封裝回到頂部組件的實現(xiàn)示例
更新時間:2022年03月17日 10:35:37 作者:柒個M
回到頂部在很多網(wǎng)頁中都可以見到,本文主要介紹了Vue3 封裝回到頂部組件的實現(xiàn)示例,文中根據(jù)實例編碼詳細介紹的十分詳盡,具有一定的參考價值,感興趣的小伙伴們可以參考一下
我們在網(wǎng)頁中應該經(jīng)常可以看到回到頂部這個功能,這個功能也比較簡單。
代碼:
<template>
<div class="page-content-scroll">
<el-backtop
target=".page-content-scroll"
>
</el-backtop>
<slot></slot>
</div>
</template>
<script>
export default {
name: "index"
}
</script>
<style scoped lang="scss">
.page-content-scroll {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
overflow-x: hidden;
}
</style>
使用:
<template>
<back-top>
<router-view/>
</back-top>
</template>
<style lang="scss">
</style>

<template>
<div>
<h1>{{ name }}</h1>
<div id="panels"></div>
</div>
</template>
<script lang="ts" setup>
import {onMounted, ref} from 'vue'
const name: string = ref('Lisa')
onMounted(() => {
const fragmentArr = document.createDocumentFragment()
const parentNode = document.getElementById('panels')
for (let i = 0; i < 200; i++) {
const elementP = document.createElement('p')
elementP.innerText = '測試' + i
fragmentArr.appendChild(elementP)
}
parentNode.appendChild(fragmentArr)
})
</script>
<style scoped>
</style>
到此這篇關于Vue3 封裝回到頂部組件的實現(xiàn)示例的文章就介紹到這了,更多相關Vue3 回到頂部內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
監(jiān)聽element-ui table滾動事件的方法
這篇文章主要介紹了監(jiān)聽element-ui table滾動事件的方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-03-03

