-
-
Save laracasts/784f03557f054b85dde073cbf2a73350 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<span v-text="count"></span> | |
</template> | |
<script> | |
import inView from 'in-viewport'; | |
export default { | |
props: ['to'], | |
data() { | |
return { | |
count: 0, | |
interval: null | |
}; | |
}, | |
computed: { | |
increment() { | |
return Math.ceil(this.end / 30); | |
} | |
}, | |
mounted() { | |
inView(this.$el, () => { | |
this.interval = setInterval(this.tick, 40); | |
}); | |
}, | |
methods: { | |
tick() { | |
if (this.count + this.increment >= this.end) { | |
this.count = this.to; | |
return clearInterval(this.interval); | |
} | |
this.count += this.increment; | |
} | |
} | |
}; | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<count :to="1000"></count> |
where is 'this.end'
guess it should be this.to. or jeff had a new data 'end' somewhere else.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
where is 'this.end'