wangdahoo / vue-animate-number

animate-number as a vue component.
https://wangdahoo.github.io/vue-animate-number/
107 stars 18 forks source link

How to use dynamic binding data? #5

Open thearabbit opened 6 years ago

thearabbit commented 6 years ago
<animate-number
                :from="from"
                :to="to"
                duration="1000"
                :formatter="formatter"
        ></animate-number>
-------------
data() {
            return {
                // Animate number
                from: 0,
                to: 123.45,
            };
        },

Don't work when change data props

matthewattanasio commented 6 years ago

I would also like to know how to use with dynamic data bindings

rudolph2907 commented 6 years ago

A work around that I've found working for me was to use the manual way, first calling reset and then start again after your data bindings updated. this.$refs.{refname}.reset(from, to) this.$refs.{refname}.start()

ihoment-amu commented 6 years ago

i have try it, but not work

ihoment-amu commented 6 years ago

eh, it must set data in reset like this this.$refs.{refname}.reset(this.from, this.to)

iMomen commented 6 years ago

A work around that I've found working for me was to use the manual way, first calling reset and then start again after your data bindings updated. this.$refs.{refname}.reset(from, to) this.$refs.{refname}.start()

this one worked for me.

<animate-number ref="projectsNumber" from="0" :to="totalNumberOfProjects"></animate-number>

and after server request update the number like this:

.then(function(response) {
this.totalNumberOfProjects = this.sectionProjectContent.title;
this.$refs.projectsNumber.reset(0, this.totalNumberOfProjects);
this.$refs.projectsNumber.start();
});
yogaukha commented 4 years ago

Plus, you have to change the mode prop to manual

<animate-number ref="projectsNumber" from="0" :to="totalNumberOfProjects" mode="manual"></animate-number>

mishengqiang commented 3 years ago
<animate-number
    :key="unique value"  
    :from="from"
    :to="to"
    duration="1000"
    :formatter="formatter"
></animate-number>

Each change key is a unique value. https://vuejs.org/v2/api/#key