Former-commit-id: 135f3b1b0c5d91988bc6cc0c1003d59be4feac7c [formerly 135f3b1b0c5d91988bc6cc0c1003d59be4feac7c [formerly 135f3b1b0c5d91988bc6cc0c1003d59be4feac7c [formerly 135f3b1b0c5d91988bc6cc0c1003d59be4feac7c [formerly b504cc2432b8edfdb9c39202c7b47edeaf01ead4 [formerly 3a24349d3b4e68b23045324db0089ebb37e83680]]]]] Former-commit-id: d88ff1b7e43d852a65ca721603cca4b59d355d4c Former-commit-id: 097ec166a6e4208044766a711e669bbab144994a Former-commit-id: d47f63f7ffa846a6a9b1280626f151b429d24e9a [formerly 2e51d3da36a1fb8530f200764d4985d1bc2ae8e7] Former-commit-id: 8209b47f361ba7842a83d82bd861d557dd5f874e Former-commit-id: 801edc0e276a938c85c9b02628edbfecdc241750 Former-commit-id: 89b774b059f50ce1c9d7253473763186b8149763 Former-commit-id: ded8753ce322a67b8538ebfa3eae2eec21b597f0 Former-commit-id: 85630e4648ac4f49b6cd0b1a8e6e9c1eb6242b35
104 lines
1.6 KiB
Vue
104 lines
1.6 KiB
Vue
<template>
|
|
<span></span>
|
|
</template>
|
|
|
|
<script>
|
|
import { CountUp } from 'countup.js'
|
|
export default {
|
|
name: 'd2-count-up',
|
|
props: {
|
|
start: {
|
|
type: Number,
|
|
required: false,
|
|
default: 0
|
|
},
|
|
end: {
|
|
type: Number,
|
|
required: true
|
|
},
|
|
decimals: {
|
|
type: Number,
|
|
required: false,
|
|
default: 0
|
|
},
|
|
duration: {
|
|
type: Number,
|
|
required: false,
|
|
default: 2
|
|
},
|
|
options: {
|
|
type: Object,
|
|
required: false,
|
|
default () {
|
|
return {}
|
|
}
|
|
},
|
|
callback: {
|
|
type: Function,
|
|
required: false,
|
|
default: () => {}
|
|
}
|
|
},
|
|
data () {
|
|
return {
|
|
c: null
|
|
}
|
|
},
|
|
watch: {
|
|
end (value) {
|
|
if (this.c && this.c.update) {
|
|
this.c.update(value)
|
|
}
|
|
}
|
|
},
|
|
mounted () {
|
|
this.init()
|
|
},
|
|
methods: {
|
|
init () {
|
|
if (!this.c) {
|
|
this.c = new CountUp(
|
|
this.$el,
|
|
this.start,
|
|
this.end,
|
|
this.decimals,
|
|
this.duration,
|
|
this.options
|
|
)
|
|
this.c.start(() => {
|
|
this.callback(this.c)
|
|
})
|
|
}
|
|
},
|
|
destroy () {
|
|
this.c = null
|
|
}
|
|
},
|
|
beforeDestroy () {
|
|
this.destroy()
|
|
},
|
|
start (callback) {
|
|
if (this.c && this.c.start) {
|
|
this.c.start(() => {
|
|
callback && callback(this.c)
|
|
})
|
|
}
|
|
},
|
|
pauseResume () {
|
|
if (this.c && this.c.pauseResume) {
|
|
this.c.pauseResume()
|
|
}
|
|
},
|
|
reset () {
|
|
if (this.c && this.c.reset) {
|
|
this.c.reset()
|
|
}
|
|
},
|
|
update (newEndVal) {
|
|
if (this.c && this.c.update) {
|
|
this.c.update(newEndVal)
|
|
}
|
|
}
|
|
}
|
|
</script>
|