Statistic 统计组件
显示统计数据。
基础用法
用于突出某个或某组数字时,如统计数值、金额、排名等,数值和标题前后都可以加icon、单位等元素。可以使用 vueuse 实现数值的变化动效
Daily active users
268,500
Total Transactions
172,000
export function StatisticBasic() { return ( <ElRow gutter={16}> <ElCol xs={24} sm={12} md={6} style={colStyle}> <ElStatistic title="Daily active users" value={268500} /> </ElCol> <ElCol xs={24} sm={12} md={6} style={colStyle}> <ElStatistic value={138} title={ <div style={{ display: "inline-flex", alignItems: "center" }}> Ratio of men to women <ElIcon size={12} style={{ marginLeft: 4 }}> <Male /> </ElIcon> </div> } suffix="/100" /> </ElCol> <ElCol xs={24} sm={12} md={6} style={colStyle}> <ElStatistic title="Total Transactions" value={172000} /> </ElCol> <ElCol xs={24} sm={12} md={6} style={colStyle}> <ElStatistic title="Feedback number" value={562} suffix={ <ElIcon style={{ verticalAlign: "-0.125em" }}> <ChatLineRound /> </ElIcon> } /> </ElCol> </ElRow> );}
倒计时
Remaining VIP time
00:00:00
Still to go until next month 00 days 00:00:00
2026-11-01
export function StatisticCountdown() { const [value] = useState(() => Date.now() + 1000 * 60 * 60 * 7); const [value1, setValue1] = useState( () => Date.now() + 1000 * 60 * 60 * 24 * 2, ); const [value2] = useState(() => dayjs().add(1, "month").startOf("month")); const reset = () => { setValue1(Date.now() + 1000 * 60 * 60 * 24 * 2); }; return ( <ElRow gutter={16}> <ElCol xs={24} sm={12} md={8} style={colStyle}> <ElCountdown title="Start to grab" value={value} /> </ElCol> <ElCol xs={24} sm={12} md={8} style={colStyle}> <ElCountdown title="Remaining VIP time" format="HH:mm:ss" value={value1} /> <ElButton type="primary" style={footerStyle} onClick={reset}> Reset </ElButton> </ElCol> <ElCol xs={24} sm={12} md={8} style={colStyle}> <ElCountdown format="DD [days] HH:mm:ss" value={value2} title={ <span style={{ display: "inline-flex", alignItems: "center" }}> <ElIcon size={12} style={{ marginRight: "4px" }}> <Calendar /> </ElIcon> Still to go until next month </span> } /> <div style={footerStyle}>{value2.format("YYYY-MM-DD")}</div> </ElCol> </ElRow> );}
统计卡片
export function StatisticCard() { return ( <div style={{ width: "100%", backgroundColor: "var(--el-fill-color)" }}> <ElRow gutter={16}> <ElCol xs={24} sm={12} md={8} style={cardColStyle}> <div style={cardStyle}> <ElStatistic value={98500} style={statisticStyle} title={cardTitle( "Daily active users", "Number of users who logged into the product in one day", )} /> <div style={statisticFooter}> <div style={footerItem}> <span>than yesterday</span> <span style={{ ...footerValue, color: "var(--el-color-success)" }}> 24% <ElIcon> <CaretTop /> </ElIcon> </span> </div> </div> </div> </ElCol> <ElCol xs={24} sm={12} md={8} style={cardColStyle}> <div style={cardStyle}> <ElStatistic value={693700} style={statisticStyle} title={cardTitle( "Monthly Active Users", "Number of users who logged into the product in one month", )} /> <div style={statisticFooter}> <div style={footerItem}> <span>month on month</span> <span style={{ ...footerValue, color: "var(--el-color-error)" }}> 12% <ElIcon> <CaretBottom /> </ElIcon> </span> </div> </div> </div> </ElCol> <ElCol xs={24} sm={12} md={8} style={cardColStyle}> <div style={cardStyle}> <ElStatistic value={72000} style={statisticStyle} title={ <div style={{ display: "inline-flex", alignItems: "center" }}> New transactions today </div> } /> <div style={statisticFooter}> <div style={footerItem}> <span>than yesterday</span> <span style={{ ...footerValue, color: "var(--el-color-success)" }}> 16% <ElIcon> <CaretTop /> </ElIcon> </span> </div> <div style={footerItem}> <ElIcon size={14}> <ArrowRight /> </ElIcon> </div> </div> </div> </ElCol> </ElRow> </div> );}
Statistic API
Statistic Attributes
| 属性名 | 说明 | 类型 | 默认值 |
|---|
| value | 数值 | number / string | 0 |
| precision | 小数精度,不足补零、超出截断 | number | 0 |
| group-separator | 千分位分隔符 | string | , |
| decimal-separator | 小数点分隔符 | string | . |
| formatter | 自定义格式化函数,传入后忽略上述格式化配置 | Function | — |
| title | 标题 | string / ReactNode | — |
| prefix | 数值前缀 | string / ReactNode | — |
| suffix | 数值后缀 | string / ReactNode | — |
| value-style | 数值样式 | object | — |
Statistic Slots
| 插槽名 | 说明 | React 写法 |
|---|
| title | 标题内容 | title |
| prefix | 前缀内容 | prefix |
| suffix | 后缀内容 | suffix |
Countdown API
Countdown Attributes
| 属性名 | 说明 | 类型 | 默认值 |
|---|
| value | 目标时间 | number / Dayjs | 0 |
| format | 倒计时显示格式 | string | HH:mm:ss |
| prefix | 数值前缀 | string / ReactNode | — |
| suffix | 数值后缀 | string / ReactNode | — |
| title | 倒计时标题 | string / ReactNode | — |
| value-style | 数值样式 | object | — |
Countdown Events
| 事件名 | 说明 | 类型 |
|---|
| onChange | 时间差变化时触发,每帧一次 | Function |
| onFinish | 倒计时结束时触发 | Function |
Countdown Slots
| 插槽名 | 说明 | React 写法 |
|---|
| prefix | 倒计时数值前缀 | prefix |
| suffix | 倒计时数值后缀 | suffix |
| title | 倒计时标题 | title |
Countdown Exposes
| 方法名 | 说明 | 类型 |
|---|
| displayValue | 当前展示文本 | object |
Countdown 格式占位符
| 占位符 | 含义 |
|---|
| Y | 年(按 365 天折算) |
| M | 月(按 30 天折算) |
| D | 天 |
| H | 小时 |
| m | 分钟 |
| s | 秒 |
| S | 毫秒 |
连续书写会自动补零(如 HH),方括号内的文本原样输出(如 [days])。