中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當前位置: 首頁 > news >正文

企業(yè)做網(wǎng)站需要花多少錢搜索引擎seo關(guān)鍵詞優(yōu)化效果

企業(yè)做網(wǎng)站需要花多少錢,搜索引擎seo關(guān)鍵詞優(yōu)化效果,電子政務(wù)門戶網(wǎng)站建設(shè)方案,id文件直接導(dǎo)入wordpress虛擬列表 - Vue3實現(xiàn)一個可動態(tài)改變高度的虛擬滾動列表 前言 在開發(fā)中經(jīng)常遇到大量的渲染列表數(shù)據(jù)問題,往往我們就只是簡單地遍歷渲染,沒有過多地去關(guān)注是否會存在性能問題,這導(dǎo)致如果數(shù)據(jù)量較大的時候,比如上萬條數(shù)據(jù)&#xff…

虛擬列表 - Vue3實現(xiàn)一個可動態(tài)改變高度的虛擬滾動列表

前言

在開發(fā)中經(jīng)常遇到大量的渲染列表數(shù)據(jù)問題,往往我們就只是簡單地遍歷渲染,沒有過多地去關(guān)注是否會存在性能問題,這導(dǎo)致如果數(shù)據(jù)量較大的時候,比如上萬條數(shù)據(jù),將會在dom中渲染上萬個節(jié)點,這將加大瀏覽器的開銷,可能會導(dǎo)致頁面卡頓,加載慢等性能問題。因此,在渲染大量數(shù)據(jù)時,可以選擇使用虛擬列表,只渲染用戶可視區(qū)域內(nèi)的dom節(jié)點。該組件已開源上傳npm,可以直接安裝使用,Git地址在文尾。

虛擬列表實現(xiàn)原理

每條固定高度

1、通過傳入組件的每條數(shù)據(jù)的高度,計算整個列表的高度,從而得到滾動列表的總高,并將總高賦值給列表。
2、監(jiān)聽滾動事件,監(jiān)聽外層容器的滾動事件,并確定可視區(qū)域內(nèi)起止數(shù)據(jù)在總數(shù)據(jù)的索引值,這可以通過scrollTop來實現(xiàn)。
3、設(shè)置數(shù)據(jù)對應(yīng)的元素,為每條數(shù)據(jù)設(shè)置一個絕對定位,其中top等于索引值乘以每條數(shù)據(jù)的高度。
4、考慮緩沖條數(shù),為了避免滑動過快產(chǎn)生空白,可以設(shè)置緩沖條數(shù)。具體來說,如果滾動到底部,可以只顯示最后N條數(shù)據(jù),如果滾動到上部,可以只顯示前N條數(shù)據(jù)。
這樣,就可以實現(xiàn)一個固定高度的虛擬列表。

每條動態(tài)高度

原理和固定高度基本一致,差別在于,用戶可以預(yù)先定義每條數(shù)據(jù)的高度,在渲染時再動態(tài)獲取每一條數(shù)據(jù)的實際高度,從而重新計算滾動列表的總體高度。

主要代碼實現(xiàn)

模板部分

showItemList循環(huán)可視區(qū)域內(nèi)的數(shù)據(jù)+緩存區(qū)的數(shù)據(jù)

<template><div class="virtual-wrap" ref="virtualWrap" :style="{width: width + 'px',height: height + 'px',}" @scroll="scrollHandle"><div class="virtual-content" :style="{height: totalEstimatedHeight +'px'}"><list-item v-for="(item,index) in showItemList" :key="item.dataIndex+index" :index="item.dataIndex" :data="item.data" :style="item.style"@onSizeChange="sizeChangeHandle"><template #slot-scope="slotProps"><slot name="slot-scope" :slotProps="slotProps"></slot></template></list-item></div></div>
</template>
獲取需要渲染的數(shù)據(jù)

通過可視區(qū)域內(nèi)的開始和結(jié)束索引,獲取需要渲染的列表數(shù)據(jù)。

const getCurrentChildren = () => {//重新計算高度estimatedHeight(props.itemEstimatedSize,props.itemCount)const [startIndex, endIndex] = getRangeToRender(props, scrollOffset.value)const items = [];for (let i = startIndex; i <= endIndex; i++) {const item = getItemMetaData(i);const itemStyle = {position: 'absolute',height: item.size + 'px',width: '100%',top: item.offset + 'px',};items.push({style: itemStyle,data: props.data[i],dataIndex:i});}showItemList.value = items;
}
獲取開始和結(jié)束索引
const getRangeToRender = (props: any, scrollOffset: any) => {const { itemCount } = props;const startIndex = getStartIndex(props, scrollOffset);const endIndex = getEndIndex(props, startIndex + props.buffCount);return [Math.max(0, startIndex -1),Math.min(itemCount - 1, endIndex ),];
};const getStartIndex = (props: any, scrollOffset: number) => {const { itemCount } = props;let index = 0;while (true) {const currentOffset = getItemMetaData(index).offset;if (currentOffset >= scrollOffset) return index;if (index >= itemCount) return itemCount;index++}
}const getEndIndex = (props: any, startIndex: number) => {const { height, itemCount } = props;// 獲取可視區(qū)內(nèi)開始的項const startItem = getItemMetaData(startIndex);// 可視區(qū)內(nèi)最大的offset值const maxOffset = Number(startItem.offset) + Number(height);// 開始項的下一項的offset,之后不斷累加此offset,知道等于或超過最大offset,就是找到結(jié)束索引了let offset = Number(startItem.offset) + startItem.size;// 結(jié)束索引let endIndex = startIndex;// 累加offsetwhile (offset <= maxOffset && endIndex < (itemCount - 1)) {endIndex++;const currentItem = getItemMetaData(endIndex);offset += currentItem.size;}// 更新已計算的項的索引值measuredData.lastMeasuredItemIndex = endIndex;return endIndex;
};
動態(tài)計算節(jié)點高度

const estimatedHeight = (defaultEstimatedItemSize = 50, itemCount: number) => {let measuredHeight = 0;const { measuredDataMap, lastMeasuredItemIndex } = measuredData;// 計算已經(jīng)獲取過真實高度的項的高度之和if (lastMeasuredItemIndex >= 0) {const lastMeasuredItem = measuredDataMap[lastMeasuredItemIndex];measuredHeight = lastMeasuredItem.offset + lastMeasuredItem.size;}// 未計算過真實高度的項數(shù)const unMeasuredItemsCount = itemCount - measuredData.lastMeasuredItemIndex - 1;// 預(yù)測總高度totalEstimatedHeight.value = measuredHeight + unMeasuredItemsCount * defaultEstimatedItemSize;
}

子組件實現(xiàn)

1、通過ResizeObserver在子節(jié)點高度變化時觸發(fā)父組件的方法,重新計算整體高度。
2、通過插槽將每條數(shù)據(jù)動態(tài)插入到列表中。

<template><div :style="style" ref="domRef"><slot name="slot-scope" :data="data"></slot></div>
</template>
<script lang="ts" setup>
import { ref, onMounted, onUnmounted } from 'vue'const emit = defineEmits(['onSizeChange']);const props = defineProps({style: {type: Object,default: () => { }},data: {type: Object,default: () => { }},index: {type: Number,default: 0}
})const domRef = ref<any>(null);
const resizeObserver:any = null;onMounted(() => {const domNode = domRef.value.children[0];emit("onSizeChange", props.index, domNode);const resizeObserver = new ResizeObserver(() => {emit("onSizeChange", props.index, domNode);});resizeObserver.observe(domNode);
})onUnmounted(() => {if (resizeObserver) {resizeObserver?.unobserve(domRef.value.children[0]);}
})
</script>

組件使用

npm install @fcli/vue-virtually-list --save-dev 來安裝在項目中使用
import VueVirtuallyList from '@fcli/vue-virtually-list';
const app=createApp(App)
app.use(VueVirtuallyList);

示例:


<div class="content"><vue-virtually-list :data="list" :height="400" :width="600" :itemCount="1000" :itemEstimatedSize="20" :buffCount="50"><template #slot-scope="{slotProps}"><div class="li">{{ slotProps.data.text }}</div></template></vue-virtually-list>
</div>
屬性屬性名稱類型可選值
data列表數(shù)據(jù)Array[]
height虛擬容器的高度number0
width虛擬容器的寬度number0
itemCount滾動列表的條數(shù)number0
itemEstimatedSize預(yù)設(shè)每行數(shù)據(jù)的高度number可不填,組件會動態(tài)計算
buffCount上下緩沖區(qū)的條數(shù)number增加快速滾動時的流暢性
#slot-scope插槽 | object | slotProps.data|
slot

例:

  <template #slot-scope="{slotProps}"><div class="li">{{ slotProps.data.text }}</div></template>

Git地址:https://gitee.com/fcli/vue-virtually-list.git

http://www.risenshineclean.com/news/23029.html

相關(guān)文章:

  • 怎么做網(wǎng)站生意線上宣傳渠道有哪些
  • 商丘網(wǎng)站制作軟件西安seo外包優(yōu)化
  • 豐臺網(wǎng)站制作營銷網(wǎng)站定制
  • 如何找人幫我做網(wǎng)站推廣網(wǎng)絡(luò)輿情監(jiān)測系統(tǒng)軟件
  • 公司做網(wǎng)站合肥網(wǎng)站制作推廣
  • 期刊網(wǎng)站建設(shè)湘潭網(wǎng)頁設(shè)計
  • 什么網(wǎng)站做ppt模板百度電話號碼查詢平臺
  • 盧灣企業(yè)微信網(wǎng)站制作seo實戰(zhàn)密碼在線閱讀
  • 手機網(wǎng)站設(shè)計案濟南百度快照推廣公司
  • 基礎(chǔ)建設(shè)龍頭股seo做的比較牛的公司
  • 網(wǎng)站效果圖怎么做seo查詢愛站
  • 怎么申請免費企業(yè)郵箱賬號上海優(yōu)化公司有哪些
  • 服務(wù)專業(yè)建設(shè)武漢官網(wǎng)優(yōu)化公司
  • 做網(wǎng)站費用多少錢域名解析ip地址
  • 小熊源碼網(wǎng)新網(wǎng)站百度seo如何做
  • 建設(shè)招標網(wǎng)網(wǎng)站網(wǎng)站關(guān)鍵詞優(yōu)化網(wǎng)站推廣
  • 自己做網(wǎng)站 搜索功能開發(fā)杭州網(wǎng)站seo優(yōu)化
  • 滄州手機建站哪家好濟南seo外包服務(wù)
  • dw做網(wǎng)站怎么設(shè)置頁面音樂網(wǎng)站大全軟件下載
  • 公司主頁怎么填寫seo軟件哪個好
  • 出國勞務(wù)信息網(wǎng)seo優(yōu)化網(wǎng)站源碼
  • 做公司網(wǎng)站需要服務(wù)器嗎上海關(guān)鍵詞排名提升
  • 一學一做短視頻網(wǎng)站杭州市優(yōu)化服務(wù)
  • 重慶網(wǎng)站空間鍵詞排名搜索引擎優(yōu)化的定義
  • 廣州各區(qū)優(yōu)化疫情防控措施seo引擎優(yōu)化公司
  • 做任務(wù)的獎金網(wǎng)站國際實時新聞
  • 國務(wù)院建設(shè)部網(wǎng)站seo數(shù)據(jù)是什么意思
  • 什么是網(wǎng)站名稱文件夾寵物美容師寵物美容培訓(xùn)學校
  • 上海專業(yè)網(wǎng)站建設(shè)機構(gòu)線上營銷平臺有哪些
  • 哪家公司建設(shè)網(wǎng)站嘉興關(guān)鍵詞優(yōu)化報價