Answer the question
In order to leave comments, you need to log in
Why does Vue.js method fire twice?
I'm trying to organize the loading of data on the page when the end is reached, for this there is:
var demo = new Vue({
el: '#demo',
data: {
gridData: null,
end : false
},
methods: {
scroll: function () {
window.onscroll = () => {
if (this.end == false) {
let bottomOfWindow = document.documentElement.scrollTop + window.innerHeight === document.documentElement.offsetHeight;
if (bottomOfWindow) {
this.end = true
console.log("end")
this.upload()
}
this.end= false
}
};
},
upload: function () {
this.errored = false;
this.loading = true;
axios
.get('http://localhost:8000')
.then(response => {
this.gridData = response.data.content;
})
//.then(response => console.log(response))
.catch(error => {
console.log(error)
this.errored = true;
})
.finally(() => {
this.loading = false;
this.time = null;
});
},
mounted: function () {
this.scroll
}
})
Answer the question
In order to leave comments, you need to log in
a request to the server is sent twice, although there is a variable that blocks this
this.end = false
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question