Within my Vue.js
application, I am looking to incorporate animations for a number/value that changes dynamically based on data retrieved from the Vuex
store.
Although I have managed to initiate the animation successfully, I am encountering an issue where the animation loop appears to be infinite and continues endlessly.
data() {
return {
interval: false,
hitsCount: 0
}
},
watch: {
hitsCount: function() {
clearInterval(this.interval);
this.interval = window.setInterval( function() {
let change = this.hitsCount / 10;
change = change >= 0 ? Math.ceil(change) : Math.floor(change);
this.hitsCount = this.hitsCount + change;
}.bind(this),20);
}
}
The corresponding template structure is as follows:
<div> {{hitsCount}} </div>
The value of hitsCount
is sourced from an API request:
this.$store.dispatch("store/data", {}).then(response => {
this.hitsCount = response.total;
.../
});
As each new request is made, the value dynamically updates. Despite these adjustments, the animation cycle persists infinitely. What could potentially be causing this issue?