el-table嵌套el-popover處理卡頓的解決
?? 罪魁禍?zhǔn)?/h2>
一個(gè)常見的場景是在表格行內(nèi)以el-popover的形式對行內(nèi)信息進(jìn)行一些業(yè)務(wù)操作。在表格分頁10條、20條的情況下頁面運(yùn)行良好,但是在分頁400條的時(shí)候會出現(xiàn)肉眼可見的卡頓。原因是表格渲染的popover組件太多了,一行如果至少3個(gè)popover組件,那么400行至少就得渲染1200個(gè)了。下面就是導(dǎo)致卡頓的通常寫法:
<el-table-column label="操作">
<template #default="{ row }">
<el-button class="button-main button-h-28">
通過
</el-button>
<popover>
<div class="popover-list-item" @click="handleLog(row)">查看日志</div>
</popover>
</template>
</el-table-column>
?? 解決方法
el-popover提供了一個(gè)虛擬觸發(fā)的功能,可以將觸發(fā)內(nèi)容和下拉內(nèi)容分開,那這樣就可以只用一個(gè)popover組件去涵蓋所有需要用到的場景。 像這個(gè)例子:
<template>
<el-table :date="data">
<el-table-column label="審核語句" min-width="150">
<template #default="{ row }">
<template v-for="(item, index) in row.childBOList" :key="item.clause">
<div class="trigger">
<div
:ref="el => (refMap[item.clause] = el)"
@click="handleRef(refMap[item.clause], item, -1)"
>
<!-- 觸發(fā)內(nèi)容1 -->
</div>
</div>
</template>
</template>
</el-table-column>
<el-table-column label="情感打標(biāo)結(jié)果" min-width="150">
<template #default="{ row }">
<div class="trigger">
<div
:ref="ref => (refMap[row.commentId] = ref)"
@click="handleRef(refMap[row.commentId], row, 0)"
>
<!-- 觸發(fā)內(nèi)容2 -->
</div>
</div>
</template>
</el-table-column>
<el-table-column label="操作" min-width="150">
<template #default="{ row }">
<div class="trigger">
<div :ref="ref => (refMap[`${row.commentId}Check`] = ref)">
<!-- 觸發(fā)內(nèi)容3 -->
</div>
</div>
</template>
</el-table-column>
</el-table>
<el-popover
v-model:visible="visiblePopover"
:virtual-ref="tempRef"
virtual-triggering
:width="popoverWidth"
>
<template v-if="popoverType === -1">
<!-- 業(yè)務(wù)邏輯1 -->
</template>
<template v-else-if="popoverType === 0">
<!-- 業(yè)務(wù)邏輯2 -->
</template>
<template v-else>
<!-- 業(yè)務(wù)邏輯3 -->
</template>
</el-popover>
</template>
<script setup>
const emotions = [
{ desc: '好評', icon: 'icon-xiaolian' },
{ desc: '中評', icon: 'icon-wubiaoqing' },
{ desc: '差評', icon: 'icon-kulian' }
]
const refMap = ref()
const tempRef = ref()
const visiblePopover = ref(false)
// -1-字句審核 0-整句審核 1-日志查看
const popoverType = ref(0)
const popoverWidth = computed(() => { [-1]: 80, [0]: 150, [1]: 90 }[popoverType.value])
const handleRef = (ref, item, type) => {
tempRef.value = ref
popoverType.value = type
if (~type) {
// ...業(yè)務(wù)邏輯1
} else {
// ...業(yè)務(wù)邏輯2、3
}
visiblePopover.value = true
}
</script>
<style lang="scss" scoped>
.trigger {
display: contents;
}
</style>現(xiàn)在,在這個(gè)例子中:
- popvoer以單例形式存在,不會出現(xiàn)400行就渲染上千個(gè)popover組件這樣的情況
- 需要一些中間狀態(tài)保存相關(guān)狀態(tài)和數(shù)據(jù)
- 不同的觸發(fā)內(nèi)容外套一層div.trigger用以去解決觸發(fā)和關(guān)閉popper的沖突(當(dāng)需要用到外部點(diǎn)擊去關(guān)閉popover的時(shí)候)
到此這篇關(guān)于el-table嵌套el-popover處理卡頓的解決的文章就介紹到這了,更多相關(guān)el-table嵌套el-popover卡頓內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue3 reactive 請求接口數(shù)據(jù)賦值后拿不到的問題及解決方案
這篇文章主要介紹了vue3 reactive 請求接口數(shù)據(jù)賦值后拿不到的問題及解決方案,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2024-04-04
vue動(dòng)態(tài)路由加載時(shí)出現(xiàn)Cannot?find?module?xxx問題
這篇文章主要介紹了vue動(dòng)態(tài)路由加載時(shí)出現(xiàn)Cannot?find?module?xxx問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-01-01
解決vue-photo-preview 異步圖片放大失效的問題
這篇文章主要介紹了解決vue-photo-preview 異步圖片放大失效的問題,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-07-07
Vue服務(wù)端渲染和Vue瀏覽器端渲染的性能對比(實(shí)例PK )
這篇文章主要介紹了Vue服務(wù)端渲染和Vue瀏覽器端渲染的性能對比(實(shí)例PK ),非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-03-03

