Skip to content

Statistic ​

Displays statistical values, supporting precision, digit grouping, prefixes/suffixes, and huge numbers as strings.

Basic usage ​

vue
<template>
  <lh-statistic
    title="Annual visits"
    :value="2384712"
  />
</template>

Precision and separator ​

precision controls the decimal places (rounded), and separator controls the digit grouping (pass an empty string to disable grouping).

vue
<template>
  <lh-statistic
    title="Rating"
    :value="4.8471"
    :precision="2"
  />
  <lh-statistic
    title="ID"
    :value="8899001"
    separator=""
  />
</template>

Prefix and suffix ​

vue
<template>
  <lh-statistic
    title="Turnover"
    :value="128600"
    prefix="¥"
    suffix="CNY"
  />
  <lh-statistic
    title="Growth rate"
    :value="12.6"
    :precision="1"
    suffix="%"
  />
</template>

Huge numbers and non-numeric text ​

A string value can carry huge numbers: integer strings beyond Number.MAX_SAFE_INTEGER go through a string formatting path that never converts to Number and loses no precision; strings that cannot be parsed as numbers are displayed as-is.

vue
<template>
  <lh-statistic
    title="Stars"
    value="Countless"
  />
  <lh-statistic
    title="Interstellar distance"
    value="9007199254740993"
  />
</template>

Slots ​

The title / prefix / suffix slots override the props of the same names.

vue
<template>
  <lh-statistic :value="1024">
    <template #title>
      <text>Custom title</text>
    </template>
    <template #prefix>
      <text>¥</text>
    </template>
    <template #suffix>
      <text>CNY</text>
    </template>
  </lh-statistic>
</template>

Props ​

PropDescriptionTypeDefault
titleValue title (shown above the value)string—
valueStatistical value; a string can carry huge numbers or signed textstring | number0
precisionDecimal placesnumber0
separatorDigit grouping separator; an empty string disables groupingstring','
prefixValue prefix, e.g. a currency symbolstring—
suffixValue suffix, e.g. a unitstring—
customClassCustom class namestring—
sxQuick layout propsLhSxProps—

Slots ​

SlotDescription
titleCustom title
prefixCustom prefix
suffixCustom suffix

Platform differences ​

  • A pure display component with no platform API usage; behaves identically on H5 and WeChat Mini Program.
  • All formatting logic (precision, digit grouping, the huge-number string path) comes from the formatStatisticValue pure function of @lh-ui/share; this repo only adds reactive glue and never copies the core implementation.
  • The value area carries aria-live="polite": on H5 screen readers politely announce the new value when value changes; Mini Program screen-reader support depends on the platform.
  • This component does not include a count-up animation. If one is added later: both setInterval and requestAnimationFrame are available on the Mini Program, but transitionend is unreliable there, so the animation tail must be aligned with setTimeout (the same approach as the message / loading transitions).