From a6b0d3d97b56cc92edd3209c86f55c2767ca02fb Mon Sep 17 00:00:00 2001 From: NikitaKA Date: Sun, 5 Sep 2021 23:46:45 +0300 Subject: [PATCH] Add optional start value property --- src/AnimatedNumber.vue | 13 +++++++++-- src/App.vue | 12 ++++++++++ tests/unit/AnimatedNumber.spec.js | 38 +++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/AnimatedNumber.vue b/src/AnimatedNumber.vue index 269f920..ebd4362 100644 --- a/src/AnimatedNumber.vue +++ b/src/AnimatedNumber.vue @@ -11,6 +11,10 @@ export default { default: '0', required: true, }, + start: { + type: [Number, String], + default: '0', + }, formatValue: { type: Function, default: value => value, @@ -38,13 +42,18 @@ export default { data() { return { animatedValue: 0, + fromValue: 0, }; }, + created() { + this.fromValue = this.start; + }, mounted() { this.animateValue(this.value); }, watch: { - value(value) { + value(value, prev) { + this.fromValue = prev; this.animateValue(value); }, }, @@ -62,7 +71,7 @@ export default { } = this; anime({ targets: this, - animatedValue: value, + animatedValue: [this.fromValue, value], duration, easing, update, diff --git a/src/App.vue b/src/App.vue index 06e6cec..5539610 100644 --- a/src/App.vue +++ b/src/App.vue @@ -4,19 +4,26 @@ +
+ + +

+