Implement infinite scroll
This commit is contained in:
parent
8ed8fe4065
commit
6ec6280fd5
@ -7,8 +7,6 @@ export default {
|
|||||||
const game = route.params.game
|
const game = route.params.game
|
||||||
const res = await fetch(`${import.meta.env.VITE_BACKEND_URL}/api/discover/${game}`)
|
const res = await fetch(`${import.meta.env.VITE_BACKEND_URL}/api/discover/${game}`)
|
||||||
const data = await res.json()
|
const data = await res.json()
|
||||||
console.log(import.meta.env)
|
|
||||||
|
|
||||||
let frontend_url = import.meta.env.VITE_INSTANCE_URL
|
let frontend_url = import.meta.env.VITE_INSTANCE_URL
|
||||||
return {
|
return {
|
||||||
data,
|
data,
|
||||||
|
@ -1,12 +1,16 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { ref, type Ref } from 'vue'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
async setup() {
|
async setup() {
|
||||||
const res = await fetch(`${import.meta.env.VITE_BACKEND_URL}/api/discover`)
|
const res = await fetch(`${import.meta.env.VITE_BACKEND_URL}/api/discover`)
|
||||||
console.log(import.meta.env)
|
let data: Ref<any[] | undefined> = ref()
|
||||||
let frontend_url = import.meta.env.VITE_INSTANCE_URL
|
let frontend_url = import.meta.env.VITE_INSTANCE_URL
|
||||||
|
data.value = await res.json()
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data: await res.json(),
|
data,
|
||||||
frontend_url,
|
frontend_url,
|
||||||
filterTags: ''
|
filterTags: ''
|
||||||
}
|
}
|
||||||
@ -47,7 +51,26 @@ export default {
|
|||||||
category.style.display = "none"
|
category.style.display = "none"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
getNextCategory() {
|
||||||
|
window.onscroll = async () => {
|
||||||
|
let bottomOfWindow = document.documentElement.scrollTop + window.innerHeight === document.documentElement.offsetHeight;
|
||||||
|
if (bottomOfWindow && this.data) {
|
||||||
|
const cursor = this.data[this.data.length - 1].cursor
|
||||||
|
if(!cursor) return
|
||||||
|
const res = await fetch(`${import.meta.env.VITE_BACKEND_URL}/api/discover/?cursor=${cursor}`)
|
||||||
|
const data = await res.json()
|
||||||
|
|
||||||
|
for (let category of data) {
|
||||||
|
this.data.push(category)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.getNextCategory()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user