I have a dynamic route, and every time I change the route multiple times the entire app freezes, and I have to exit the website, even the browser is frozen until i exit website.
Those are the route related functions
watch: {
$route(to, from) {
if (to.path != from.path) {
this.initialize();
}
},
},
created() {
window.addEventListener("scroll", this.onScroll);
this.initialize();
},
destroyed() {
window.removeEventListener("scroll", this.onScroll);
},
and those are the additional functions with the scroll listener:
onScroll(e) {
// I dont know why, found it
let scrollPos =
Math.max(
window.pageYOffset,
document.documentElement.scrollTop,
document.body.scrollTop
) + window.innerHeight;
let bottomPos = document.documentElement.offsetHeight - 100; // 100 is the offset
if (scrollPos >= bottomPos && !this.loading) {
this.loadRandomWords(this.wordsAdd);
}
},
initialize() {
let category = this.$route.params.name;
db.collection("categories")
.where("name", "==", category)
.get()
.then((snap) => {
this.categoryId = snap.docs[0].id;
this.wordIDs = snap.docs[0].data().words;
this.wordsToDisplay = [];
this.loadRandomWords(this.wordsAdd);
});
},
},
Aucun commentaire:
Enregistrer un commentaire