Skip to content

Commit

Permalink
Feat: Countup display fixed value (louislam#4266)
Browse files Browse the repository at this point in the history
  • Loading branch information
chakflying authored Dec 21, 2023
1 parent c9fe6b5 commit d830fa4
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/components/CountUp.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<span v-if="isNum" ref="output">{{ output }}</span> <span v-if="isNum">{{ unit }}</span>
<span v-if="isNum" ref="output">{{ outputFixed }}</span> <span v-if="isNum">{{ unit }}</span>
<span v-else>{{ value }}</span>
</template>

Expand Down Expand Up @@ -37,6 +37,19 @@ export default {
isNum() {
return typeof this.value === "number";
},
outputFixed() {
if (typeof this.output === "number") {
if (this.output < 1) {
return "<1";
} else if (Number.isInteger(this.output)) {
return this.output;
} else {
return this.output.toFixed(2);
}
} else {
return this.output;
}
}
},
watch: {
Expand Down

0 comments on commit d830fa4

Please sign in to comment.