I have a component called B-DATEPICKER that gives me BUEFY to display a date field:
The problem I'm having is when I call the function from here so that when the date changes I call the DetailTracking() function but the web page freezes and doesn't respond.
<b-datepicker
v-model="dateFilter"
@input="detailTracking()"
icon="calendar" expanded>
</b-datepicker>
What causes this problem? Note: the function works correctly because when I call it from a setInterval if it calls that function:
this.interval = setInterval(() => {
this.detailTracking();
}, 30000);
Is there another way to call the function when changing the date?
UPDATE
detailTracking(track) {
this.isEmpty = false;
this.isLoadingContainer = true;
this.cont += 1;
if(this.cont <= 1){
this.dateFilter = track.date;
this.licenseName = track.license;
}
this.dateFilter = new Date(Date.parse(this.dateFilter))
this.nPositions = 0;
const data = {
param: this.licenseName,
date: moment(this.dateFilter).format('YYYY-MM-DD'),
};
this.axios.post('tracking/filter-vehicle/', data)
.then((response) => {
this.isDetail = true;
this.tracking = response.data.results;
if(this.tracking.length !== 0) {
this.tracking.forEach((t) => {
t.position = { lat: t.latitude, lng: t.longitude };
this.nPositions += 1;
});
this.pointsGps = this.tracking.map((d) => {
const p = {
lat: parseFloat(d.latitude, 10),
lng: parseFloat(d.longitude, 10),
};
return p;
});
this.center = this.tracking[0].position;
this.isLoadingContainer = false;
}
else {
this.isEmpty = true;
this.copytracking.forEach((l)=>{
if(l.license === this.licenseName){
this.tracking = [l];
}
});
this.tracking.forEach((t) => {
t.position = { lat: t.latitude, lng: t.longitude };
this.nPositions += 1;
});
this.pointsGps = this.tracking.map((d) => {
const p = {
lat: parseFloat(d.latitude, 10),
lng: parseFloat(d.longitude, 10),
};
return p;
});
this.center = this.tracking[0].position;
this.isLoadingContainer = false;
}
})
.catch(error => console.log(error));
},
The problem was the following:
this made a change to the v-model this.datafilter every time the function was executed and as it made a change it again called @input and so on infinitely So so that it only runs once I put it above where I only want it to run once time:
This way it is working correctly :D