Vue Numeric Count Animation

1.0.13 · active · verified Sun Apr 19

vue-count-to is a lightweight, dependency-free Vue component designed to animate the counting of numbers from a `startVal` to an `endVal` over a specified `duration`. It automatically determines whether to count up or down and supports customization of the easing function. Key features include the ability to set decimal places, separators, prefixes, and suffixes, and it offers `autoplay` functionality that triggers a re-count when `startVal` or `endVal` props change. The current stable version, as of the provided information, is `1.0.13`, indicating a mature and stable release. While a specific release cadence isn't explicitly mentioned in the documentation, its long-standing presence and continued use suggest it receives maintenance. Its primary differentiator is its simplicity and minimal footprint, making it ideal for straightforward numeric animations in Vue 2 applications, without the overhead of more complex animation libraries. It also supports Vue SSR.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to import and register the `countTo` component, set initial and target values, and include basic formatting options like decimals, separators, and prefixes.

<template>
  <div>
    <h1>Live Count:</h1>
    <countTo :startVal='startVal' :endVal='endVal' :duration='3000' :decimals="2" separator="," prefix="$"></countTo>
    <button @click="startCount">Start New Count</button>
  </div>
</template>

<script>
  import countTo from 'vue-count-to';

  export default {
    components: { countTo },
    data () {
      return {
        startVal: 0,
        endVal: 2025.56
      }
    },
    methods: {
      startCount() {
        // Example of manually changing values to trigger re-count if autoplay is true
        // Or manually start if autoplay is false via a ref (not shown in basic example)
        this.startVal = Math.floor(Math.random() * 100);
        this.endVal = Math.floor(Math.random() * 10000);
      }
    }
  }
</script>

view raw JSON →