el-table渲染慢卡頓問題最優(yōu)解決方案
1.如下圖,需要綁定兩個(gè)id,第一個(gè)id是需要浮動(dòng)的元素,加上scroll方法監(jiān)聽滑塊變化,第二個(gè)id是其子元素。
2.給eagleMapContainer設(shè)置overflow屬性和滑塊樣式,CSS參考如下
#eagleMapContainer{ overflow-y: auto; margin-top: 10px; min-height: 150px; max-height: 600px; } #eagleMapContainer::-webkit-scrollbar { width: 6px; /*對(duì)垂直流動(dòng)條有效*/ height: 6px; } #eagleMapContainer::-webkit-scrollbar-track{ background-color:rgba(0,0,0,0.1); } #eagleMapContainer::-webkit-scrollbar-thumb{ border-radius: 6px; background-color: rgba(0,0,0,0.2); } /*定義右下角匯合處的樣式*/ #eagleMapContainer::-webkit-scrollbar-corner { background:rgba(0,0,0,0.2); }
3.在methods添加如下方法監(jiān)聽滑動(dòng)
hanldeScroll(e) { // 獲取eagleMapContainer的真實(shí)高度 const boxHeight = document.getElementById('eagleMapContainer').offsetHeight // 獲取table_list的真實(shí)高度(浮動(dòng)內(nèi)容的真實(shí)高度) const tableHeight = document.getElementById('table_list').offsetHeight // boxHeight和滑塊浮動(dòng)的高度相差小于50 && 不在加載中 && 不是最后一頁(yè) if (tableHeight - (e.target.scrollTop + boxHeight) < 50 && !this.loading && this.listPage < (this.tableList.length / 300)) { // 第一次觸發(fā)時(shí),記錄滑塊高度 // data里scrollTop,listPage默認(rèn)為0 if (!this.scrollTop) { this.scrollTop = e.target.scrollTop } // 觸發(fā)下拉加載更多 this.queryMoreStat(true, tableHeight, boxHeight) } else if (e.target.scrollTop === 0 && !this.loading) { // 如果滑塊上拉到頂部,則向上加載300條 this.queryMoreStat(false, tableHeight, boxHeight) } }
4.在methods添加如下方法,滑塊置頂或觸底(實(shí)現(xiàn)原理:始終只渲染當(dāng)前300條和前后的300條,一共900條數(shù)據(jù))
queryMoreStat(type, tableHeight, boxHeight) { this.loading = true // 觸底加載 if (type) { this.listPage = this.listPage + 1 const centerPage = this.listPage * 300 const startPage = centerPage >= 300 ? centerPage - 300 : centerPage const endPage = centerPage + 600 const newList = this.tableList.slice(startPage, endPage) if (this.listPage > 0) { const box = document.getElementById('eagleMapContainer') // 視圖跳到觸發(fā)的數(shù)據(jù),補(bǔ)回50的高度差值 box.scrollTop = this.scrollTop + 50 } this.list = newList } else { // 置頂加載 if (this.listPage > 0) { this.listPage = this.listPage - 1 const centerPage = this.listPage * 300 const startPage = centerPage >= 300 ? centerPage - 300 : centerPage const endPage = centerPage + 600 const newList = this.tableList.slice(startPage, endPage) if (this.listPage > 0) { const box = document.getElementById('eagleMapContainer') box.scrollTop = tableHeight - this.scrollTop - boxHeight } this.list = newList } else { this.list = this.tableList.slice(0, 300) } } this.$nextTick(() => { this.loading = false }) }
到此這篇關(guān)于el-table渲染慢卡頓問題最優(yōu)解決方案的文章就介紹到這了,更多相關(guān)el-table渲染慢卡頓內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Vue2實(shí)現(xiàn)數(shù)字滾動(dòng)翻頁(yè)效果的示例代碼
這篇文章主要為大家詳細(xì)介紹了Vue2如何實(shí)現(xiàn)數(shù)字滾動(dòng)翻頁(yè)效果,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,有需要的小伙伴可以參考一下2024-03-03關(guān)于this.$refs獲取不到dom的可能原因及解決方法
這篇文章主要介紹了關(guān)于this.$refs獲取不到dom的可能原因及解決方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-11-11Vue實(shí)現(xiàn)的父組件向子組件傳值功能示例
這篇文章主要介紹了Vue實(shí)現(xiàn)的父組件向子組件傳值功能,結(jié)合完整實(shí)例形式簡(jiǎn)單分析了vue.js組件傳值的相關(guān)操作技巧,需要的朋友可以參考下2019-01-01vue-resource?獲取本地json數(shù)據(jù)404問題的解決
這篇文章主要介紹了vue-resource?獲取本地json數(shù)據(jù)404問題的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10