Statistic统计数值
Statistic 统计数值
展示统计数值。
何时使用
-
当需要突出某个或某组数字时
-
当需要展示带描述的统计类数据时使用
代码演示
基本用法
简单展示
<template> <a-row> <a-col :span="12"> <a-statistic title="Active Users" :value="112893" style="margin-right: 50px" /> </a-col> <a-col :span="12"> <a-statistic title="Account Balance (CNY)" :precision="2" :value="112893" /> </a-col> </a-row></template>
在卡片中使用
在卡片中展示统计数值。
<template> <div style="background: #ececec; padding: 30px"> <a-row :gutter="16"> <a-col :span="12"> <a-card> <a-statistic title="Feedback" :value="11.28" :precision="2" suffix="%" :value-style="{ color: '#3f8600' }" style="margin-right: 50px" > <template #prefix> <arrow-up-outlined /> </template> </a-statistic> </a-card> </a-col> <a-col :span="12"> <a-card> <a-statistic title="Idle" :value="9.3" :precision="2" suffix="%" class="demo-class" :value-style="{ color: '#cf1322' }" > <template #prefix> <arrow-down-outlined /> </template> </a-statistic> </a-card> </a-col> </a-row> </div></template><script lang="ts">import { ArrowUpOutlined, ArrowDownOutlined } from '@ant-design/icons-vue';import { defineComponent } from 'vue';export default defineComponent({ components: { ArrowUpOutlined, ArrowDownOutlined, },});</script>
单位
通过前缀和后缀添加单位。
<template> <a-row :gutter="16"> <a-col :span="12"> <a-statistic title="Feedback" :value="1128" style="margin-right: 50px"> <template #suffix> <like-outlined /> </template> </a-statistic> </a-col> <a-col :span="12"> <a-statistic title="Unmerged" :value="93" class="demo-class"> <template #suffix> <span>/ 100</span> </template> </a-statistic> </a-col> </a-row></template><script lang="ts">import { LikeOutlined } from '@ant-design/icons-vue';import { defineComponent } from 'vue';export default defineComponent({ components: { LikeOutlined, },});</script>
倒计时
倒计时组件。
<template> <a-row :gutter="16"> <a-col :span="12"> <a-statistic-countdown title="Countdown" :value="deadline" style="margin-right: 50px" @finish="onFinish" /> </a-col> <a-col :span="12"> <a-statistic-countdown title="Million Seconds" :value="deadline" format="HH:mm:ss:SSS" style="margin-right: 50px" /> </a-col> <a-col :span="24" style="margin-top: 32px"> <a-statistic-countdown title="Day Level" :value="deadline" format="D 天 H 时 m 分 s 秒" /> </a-col> </a-row></template><script lang="ts">import { defineComponent } from 'vue';export default defineComponent({ setup() { const onFinish = () => { console.log('finished!'); }; return { deadline: Date.now() + 1000 * 60 * 60 * 24 * 2 + 1000 * 30, onFinish, }; },});</script>
API
Statistic
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| decimalSeparator | 设置小数点 | string | . |
|---|---|---|---|
| formatter | 自定义数值展示 | v-slot | ({value}) => VNode | - | |---|---|---|---|
| groupSeparator | 设置千分位标识符 | string | , |
|---|---|---|---|
| precision | 数值精度 | number | - |
|---|---|---|---|
| prefix | 设置数值的前缀 | string | v-slot | - | |---|---|---|---|
| suffix | 设置数值的后缀 | string | v-slot | - | |---|---|---|---|
| title | 数值的标题 | string | v-slot | - | |---|---|---|---|
| value | 数值内容 | string | number | - | |---|---|---|---|
| valueStyle | 设置数值的样式 | style | - |
|---|---|---|---|
Statistic.Countdown
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| format | 格式化倒计时展示,参考 moment | string | ‘HH:mm:ss’ |
|---|---|---|---|
| prefix | 设置数值的前缀 | string | v-slot | - | |---|---|---|---|
| suffix | 设置数值的后缀 | string | v-slot | - | |---|---|---|---|
| title | 数值的标题 | string | v-slot | - | |---|---|---|---|
| value | 数值内容 | number | moment | - | |---|---|---|---|
| valueStyle | 设置数值的样式 | style | - |
|---|---|---|---|
Statistic.Countdown 事件
| 事件名称 | 说明 | 回调参数 |
|---|---|---|
| finish | 倒计时完成时触发 | () => void |
|---|---|---|
