電腦視頻制作軟件搜索引擎優(yōu)化的定義
背景
對(duì)于后臺(tái)管理系統(tǒng),數(shù)據(jù)的展示形式大多都是通過表格,常常會(huì)出現(xiàn)的一種場景,從表格跳到二級(jí)頁面,再返回上一頁時(shí),需要緩存當(dāng)前的頁碼和滾動(dòng)條的位置,以為使用keep-alive就能實(shí)現(xiàn)這兩種訴求,實(shí)際開發(fā)的時(shí)候,才發(fā)現(xiàn)?keep-alive組件是不會(huì)緩存滾動(dòng)位置的。
實(shí)現(xiàn)table緩存滾動(dòng)條
先使用keep-alive
<template><el-main><router-view v-slot="{ Component, route }"><transition appear name="fade-transform" mode="out-in"><keep-alive :include="keepAliveStore.keepAliveName"><component :is="Component" :key="route.path" v-if="isRouterShow" /></keep-alive></transition></router-view></el-main>
</template>
在二次封裝的列表組件中,監(jiān)聽?activated 和?deactivated 生命周期,設(shè)置表格的滾動(dòng)條
// 實(shí)現(xiàn)element table緩存滾動(dòng)位置
const tableRef = ref<InstanceType<typeof ElTable>>(); // 表格的實(shí)例
const scrollPosition = ref<number | null>(null); // 記錄滾動(dòng)條的位置
// 頁面激活時(shí)
onActivated(() => {if (scrollPosition.value) {nextTick(() => {// 設(shè)置表格的滾動(dòng)條位置tableRef.value?.scrollBarRef.setScrollTop(scrollPosition.value);scrollPosition.value = null;});}
});
// 頁面離開時(shí)
onDeactivated(() => {nextTick(() => {// 記錄滾動(dòng)條的位置scrollPosition.value = tableRef.value?.scrollBarRef.wrapRef.scrollTop;});
});
呈現(xiàn)的效果: