Skip to content

Commit

Permalink
fix: 修复数字动画 end变更后不重新触发的bug、优化格式化函数
Browse files Browse the repository at this point in the history
  • Loading branch information
yuntian001 committed Sep 15, 2022
1 parent e978ac2 commit c9abbf3
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/components/meNumber.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<template>
<span>
<span class="prefix">{{ numberInfo.prefix }}</span>
<span class="output">{{
props.format ? props.format(+output.toFixed(numberInfo.decimals)) : output.toFixed(numberInfo.decimals)
}}</span>
<span class="output">{{ format ? format(output, numberInfo.decimals) : output }}</span>
<span class="suffix">{{ numberInfo.suffix }}</span>
</span>
</template>

<script setup lang="ts">
import formatNumber from 'format-number';
import { PropType } from 'vue';
import { TransitionPresets, useTransition, EasingFunction } from '@vueuse/core';
const props = defineProps({
Expand All @@ -26,8 +25,8 @@ const props = defineProps({
default: 'easeOutExpo',
},
format: {
type: Function as PropType<(number: number) => string | number>,
default: new Intl.NumberFormat('zh').format,
type: Function as PropType<(number: number, decimals: number) => string | number>,
default: (number: number, decimals: number) => formatNumber({ truncate: decimals, padRight: decimals })(number),
},
});
const emit = defineEmits(['finished', 'started']);
Expand Down Expand Up @@ -69,6 +68,6 @@ const getFormatInfo = (value: number | [number, string?, string?]) => {
watch(
() => props.end,
(end) => Object.assign(numberInfo, getFormatInfo(end ?? props.start)),
{ immediate: true },
{ immediate: true, deep: true },
);
</script>

0 comments on commit c9abbf3

Please sign in to comment.