Commit 94b2222c085e30cbc4a7a49dfac13af15aec98b9

Authored by 啝裳
Committed by GitHub
1 parent 502cc270

perf: improve countTo (#499)

src/components/CountTo/src/index.vue
1 1 <template>
2   - <span>
  2 + <span :style="{ color: color }">
3 3 {{ displayValue }}
4 4 </span>
5 5 </template>
... ... @@ -22,6 +22,7 @@
22 22 timestamp: number | null;
23 23 rAF: any;
24 24 remaining: number | null;
  25 + color: any;
25 26 }>({
26 27 localStartVal: props.startVal,
27 28 displayValue: formatNumber(props.startVal),
... ... @@ -32,6 +33,7 @@
32 33 timestamp: null,
33 34 remaining: null,
34 35 rAF: null,
  36 + color: null,
35 37 });
36 38  
37 39 onMounted(() => {
... ... @@ -52,10 +54,11 @@
52 54 });
53 55  
54 56 function start() {
55   - const { startVal, duration } = props;
  57 + const { startVal, duration, color } = props;
56 58 state.localStartVal = startVal;
57 59 state.startTime = null;
58 60 state.localDuration = duration;
  61 + state.color = color;
59 62 state.paused = false;
60 63 state.rAF = requestAnimationFrame(count);
61 64 }
... ...
src/components/CountTo/src/props.ts
... ... @@ -13,6 +13,10 @@ export const countToProps = {
13 13 return value >= 0;
14 14 },
15 15 },
  16 + color: {
  17 + type: String as PropType<string>,
  18 + require: false,
  19 + },
16 20 decimal: propTypes.string.def('.'),
17 21 separator: propTypes.string.def(','),
18 22 prefix: propTypes.string.def(''),
... ...
src/views/demo/comp/count-to/index.vue
... ... @@ -2,16 +2,35 @@
2 2 <PageWrapper title="数字动画示例">
3 3 <Card>
4 4 <CardGrid class="count-to-demo-card">
5   - <CountTo prefix="$" :startVal="1" :endVal="200000" :duration="8000" />
  5 + <CountTo prefix="$" :color="'#409EFF'" :startVal="1" :endVal="200000" :duration="8000" />
6 6 </CardGrid>
7 7 <CardGrid class="count-to-demo-card">
8   - <CountTo suffix="$" :startVal="1" :endVal="300000" :decimals="2" :duration="6000" />
  8 + <CountTo
  9 + suffix="$"
  10 + :color="'red'"
  11 + :startVal="1"
  12 + :endVal="300000"
  13 + :decimals="2"
  14 + :duration="6000"
  15 + />
9 16 </CardGrid>
10 17 <CardGrid class="count-to-demo-card">
11   - <CountTo suffix="$" :startVal="1" :endVal="400000" :duration="7000" />
  18 + <CountTo
  19 + suffix="$"
  20 + :color="'rgb(0,238,0)'"
  21 + :startVal="1"
  22 + :endVal="400000"
  23 + :duration="7000"
  24 + />
12 25 </CardGrid>
13 26 <CardGrid class="count-to-demo-card">
14   - <CountTo separator="-" :startVal="10000" :endVal="500000" :duration="8000" />
  27 + <CountTo
  28 + separator="-"
  29 + :color="'rgba(138,43,226,.6)'"
  30 + :startVal="10000"
  31 + :endVal="500000"
  32 + :duration="8000"
  33 + />
15 34 </CardGrid>
16 35 </Card>
17 36 </PageWrapper>
... ...