ottenuto questo lavoro come un componente personalizzato: https://jsfiddle.net/5nobcLq0/5/
html
<body>
<input v-model="number">
<animated-number :number="number"></animated-number>
</body>
js
Vue.component('animated-number',{
template:"{{displayNumber}}",
props:{'number':{default:0}},
data: function(){
return {
displayNumber:0,
interval:false
}
},
ready:function(){
this.displayNumber = this.number ? this.number : 0;
},
watch:{
number: function(){
clearInterval(this.interval);
if(this.number == this.displayNumber){
return;
}
this.interval = window.setInterval(function(){
if(this.displayNumber != this.number){
var change = (this.number - this.displayNumber)/10;
change = change >= 0 ? Math.ceil(change) : Math.floor(change);
this.displayNumber = this.displayNumber + change;
}
}.bind(this), 20);
}
}
})
new Vue({
el:'body',
});
Ho iniziato a rispondere ma sono diretto verso la notte. Ecco a cosa stavo lavorando: https://jsfiddle.net/5nobcLq0/1/ Fondamentalmente, l'idea è di mantenere il numero separato dal numero visualizzato, e se sono diversi incrementano il numero di visualizzazione verso il numero reale. Penso che idealmente questo sarebbe un componente a sé stante, o una direttiva come 'v-animate'. Lo guarderò più domani – Jeff
Ho dato un'occhiata a v-animate ma non ho trovato nulla che potesse aiutarmi – user3662307