In my vuejs-application I want to animate a number/value when it changes. The value is based on a response from the vuex-store.
so I've got the animation running, but for some reason the animation loop is infinite and just continues all the time.
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 template is simply:
<div> {{hitsCount}} </div> The value hitsCount comes from a request:
this.$store.dispatch("store/data", {}).then(response => { this.hitsCount = response.total; .../ }); the value changes each time there is a new request.
As mentioned before, the animation starts right away and keeps counting endlessly - what am I missing here?