Skip to content

Instantly share code, notes, and snippets.

@dmjcomdem
Created May 26, 2022 10:59
Show Gist options
  • Save dmjcomdem/90457d282b353e5f4743e044b44594b8 to your computer and use it in GitHub Desktop.
Save dmjcomdem/90457d282b353e5f4743e044b44594b8 to your computer and use it in GitHub Desktop.
Небольшой пример отрисовки данных при прокручивании блока/таблицы
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