Created
May 26, 2022 10:59
-
-
Save dmjcomdem/90457d282b353e5f4743e044b44594b8 to your computer and use it in GitHub Desktop.
Небольшой пример отрисовки данных при прокручивании блока/таблицы
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data: () => ({ | |
placements: [], | |
placementsData: [], | |
limit: 10, | |
step: 0, | |
isRenderAllItems: false, | |
isScroll: false | |
}), | |
methods: { | |
async fetchData() { | |
this.placementsData = await api.getPlacements(); | |
}, | |
scrollHandler() { | |
const tableRef = this.$refs.table; | |
if (tableRef.scrollTop + tableRef.clientHeight >= tableRef.scrollHeight) { | |
if (this.placements?.length != this.placementsData?.length) { | |
this.step += 1; | |
this.isScroll = true; | |
const nextStep = this.step * this.limit; | |
const nextPlacements = this.placementsData.slice(nextStep, nextStep + this.limit); | |
this.placements.push(...nextPlacements); | |
setTimeout(() => (this.isScroll = false), 600); | |
} else { | |
this.isRenderAllItems = true; | |
} | |
} | |
}, | |
}, | |
mounted() { | |
this.fetchData() | |
this.$refs.table.addEventListener('scroll', this.scrollHandler); | |
}, | |
mounted() { | |
this.$refs.table.addEventListener('scroll', this.scrollHandler); | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment