减少层级
Former-commit-id: 889b557de9234ebb4364ebb87f5bf8b0935294eb [formerly 889b557de9234ebb4364ebb87f5bf8b0935294eb [formerly 889b557de9234ebb4364ebb87f5bf8b0935294eb [formerly 889b557de9234ebb4364ebb87f5bf8b0935294eb [formerly 41b59da80ab4c5c0b9eceeec8fd2f527d22c4ab8 [formerly 3dc1bcda38f391962e102a990c2b68b7a33d4683]]]]] Former-commit-id: 3cd64e384a81021adeab4674894f3e4ba934924a Former-commit-id: 6c1d5c80613ac406276127f3b01566ace11becab Former-commit-id: fb1dae74ec5eea07c96632f6e8841b1bc42a614a [formerly 159c5ea89b386d484b2ef90733075633b156d87e] Former-commit-id: 5be175c876d576777072d4430a8520fc7b255112 Former-commit-id: ec65f0871fca703dbbc7a428ca9e4b582043c361 Former-commit-id: 80b73945bd350373ce7e3d15b8f0432c1427d8e3 Former-commit-id: cc2112baadf022e42428dd0019a764e266570b21 Former-commit-id: b7c059087a58e03c0d954af34b30f94b3e03b60c
This commit is contained in:
103
src/components/d2-count-up/index.vue
Normal file
103
src/components/d2-count-up/index.vue
Normal file
@@ -0,0 +1,103 @@
|
||||
<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>
|
||||
Reference in New Issue
Block a user