Skip to content

统计数值 Statistic

展示统计数值

何时使用

  • 当需要突出某个或某组数字时
  • 当需要展示带描述的统计类数据时使用

基本使用

Show Code
vue
<template>  <Row>  <Col :span="12">  <Statistic title="Active Users" :value="112893" />  </Col>  <Col :span="12">  <Statistic title="Account Balance (CNY)" :precision="2" :value="112893" />  </Col>  </Row> </template>

添加前缀和后缀

Show Code
vue
<script setup lang="ts"> import { LikeOutlined } from '@ant-design/icons-vue' </script> <template>  <Row :gutter="16">  <Col :span="12">  <Statistic title="Feedback" :value="1128">  <template #suffix>  <LikeOutlined />  </template>  </Statistic>  </Col>  <Col :span="12">  <Statistic title="Unmerged" :value="90">  <template #suffix>  <span>%</span>  </template>  </Statistic>  </Col>  </Row> </template>

在卡片中使用

Show Code
vue
<script setup lang="ts"> import { ArrowUpOutlined, ArrowDownOutlined } from '@ant-design/icons-vue' </script> <template>  <div style="width: 425px; background: #ececec; padding: 30px; border-radius: 8px;">  <Row :gutter="16">  <Col :span="12">  <Card>  <Statistic  title="Feedback"  :value="11.28"  :precision="2"  suffix="%"  :value-style="{ color: '#3f8600' }"  style="margin-right: 50px"  >  <template #prefix>  <ArrowUpOutlined />  </template>  </Statistic>  </Card>  </Col>  <Col :span="12">  <Card>  <Statistic title="Idle" :value="9.3" :precision="2" suffix="%" :value-style="{ color: '#cf1322' }">  <template #prefix>  <ArrowDownOutlined />  </template>  </Statistic>  </Card>  </Col>  </Row>  </div> </template>

自定义数值样式

Worth
$1,600,000/ 天
Show Code
vue
<template>  <Statistic  title="Worth"  :value="1600000"  :value-style="{ color: '#3f8600' }"  prefix="$"  suffix="/ 天" /> </template>

设置数值精度

Precision
100,000,000.10
Show Code
vue
<template>  <Statistic  title="Precision"  :value="100000000.1"  :precision="2" /> </template>

自定义分隔符

Precision
100;000;000.100
Show Code
vue
<template>  <Statistic  title="Precision"  :value="100000000.1"  separator=";"  :precision="3" /> </template>

自定义数值展示

Formatter
1年有 365 天
Show Code
vue
<script setup lang="ts"> function formatter (value: string): string {  console.log('value', value)  return '1年有 ' + value + ' 天' } </script> <template>  <Statistic  title="Formatter"  :value="365"  :value-style="{ color: '#1677ff' }"  :formatter="formatter" /> </template>

APIs

Statistic

参数说明类型默认值
title数值的标题stringundefined
value数值的内容string | number | slotundefined
valueStyle设置数值的样式CSSProperties{}
precision数值精度number0
prefix设置数值的前缀string | slotundefined
suffix设置数值的后缀string | slotundefined
separator设置千分位标识符string,
formatter自定义数值展示Function(value: string) => value

Slots

名称说明类型
title自定义数值的标题v-slot:title
default自定义数值的内容v-slot:default
prefix自定义数值的前缀v-slot:prefix
suffix自定义数值的后缀v-slot:suffix