89 lines
1.8 KiB
Vue
89 lines
1.8 KiB
Vue
<template>
|
|
<div class="demo">
|
|
<div class="row">
|
|
<button type="button" class="btn" @click="randomize" v-text="'换一个数值'" />
|
|
</div>
|
|
|
|
<div class="list">
|
|
<div class="item">
|
|
<span class="label" v-text="'默认(自动小数位)'" />
|
|
<animated-number class="value" :value="value" :duration="800" thousands />
|
|
</div>
|
|
<div class="item">
|
|
<span class="label" v-text="'固定两位小数'" />
|
|
<animated-number class="value" :value="value" :decimals="2" :duration="800" thousands />
|
|
</div>
|
|
<div class="item">
|
|
<span class="label" v-text="'自定义分隔符 + 线性缓动'" />
|
|
<animated-number
|
|
class="value"
|
|
:value="value"
|
|
:duration="1200"
|
|
:decimals="0"
|
|
thousands
|
|
separator=" "
|
|
easing="linear"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import { ref } from "vue";
|
|
import { AnimatedNumber } from "timi-web";
|
|
|
|
/** 改动 value 会触发滚动过渡,注意所有实例共用同一个值以便对比缓动差异。 */
|
|
const value = ref(12345);
|
|
|
|
function randomize() {
|
|
value.value = Math.round(Math.random() * 900000 + 10000);
|
|
}
|
|
</script>
|
|
|
|
<style lang="less" scoped>
|
|
.demo {
|
|
.row {
|
|
margin-bottom: 1.25rem;
|
|
}
|
|
|
|
.btn {
|
|
padding: .25rem .75rem;
|
|
font-size: .75rem;
|
|
cursor: pointer;
|
|
border: 1px solid var(--vp-c-divider);
|
|
border-radius: .375rem;
|
|
color: var(--vp-c-text-1);
|
|
background: var(--vp-c-bg-soft);
|
|
|
|
&:hover {
|
|
color: var(--vp-c-brand-1);
|
|
border-color: var(--vp-c-brand-1);
|
|
}
|
|
}
|
|
|
|
.list {
|
|
display: grid;
|
|
gap: .75rem;
|
|
}
|
|
|
|
.item {
|
|
display: flex;
|
|
gap: 1rem;
|
|
align-items: baseline;
|
|
}
|
|
|
|
.label {
|
|
width: 14rem;
|
|
font-size: .75rem;
|
|
color: var(--vp-c-text-2);
|
|
}
|
|
|
|
.value {
|
|
font-size: 1.25rem;
|
|
font-weight: 600;
|
|
color: var(--vp-c-brand-1);
|
|
}
|
|
}
|
|
</style>
|