Vue CountUp v2 Component

4.0.0 · maintenance · verified Sun Apr 19

vue-countup-v2 is a Vue.js component that acts as a wrapper for the popular CountUp.js library, providing an easy way to animate numerical values in Vue applications. The current stable version, 4.0.0, aims for straightforward integration by encapsulating CountUp.js functionality within a reusable `<ICountUp>` component. Developers can pass properties like `delay`, `endVal`, and a comprehensive `options` object directly to the component, mirroring the `CountUp.js` API. It exposes `CountUp.js` instance methods (such as `update`, `start`, `reset`) via an `onReady` event callback, allowing programmatic control over the animation. The package's release cadence is not fixed but generally aligns with updates to its core dependency, `CountUp.js`, and was primarily developed for Vue 2 applications, as suggested by the "v2" in its name. Its key differentiator is simplifying the process of adding numerical animations to Vue 2 projects by abstracting the `CountUp.js` lifecycle.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to integrate `ICountUp` into a Vue 2 component, passing dynamic props and accessing the `CountUp.js` instance via the `@ready` event to perform an update.

<template>
  <div class="iCountUp">
    <ICountUp
      :delay="delay"
      :endVal="endVal"
      :options="options"
      @ready="onReady"
    />
  </div>
</template>

<script type="text/babel">
  import ICountUp from 'vue-countup-v2';

  export default {
    name: 'DemoCountUp',
    components: {
      ICountUp
    },
    data() {
      return {
        delay: 1000,
        endVal: 120500,
        options: {
          useEasing: true,
          useGrouping: true,
          separator: ',',
          decimal: '.',
          prefix: '$',
          suffix: ' USD'
        }
      };
    },
    methods: {
      onReady: function(instance, CountUp) {
        // The CountUp.js instance is available here to call its methods
        console.log('CountUp instance ready:', instance);
        console.log('CountUp library constructor:', CountUp);
        // Example: Update the value after 3 seconds
        setTimeout(() => {
          instance.update(this.endVal + 25000);
        }, 3000);
      }
    },
    mounted() {
      console.log('Component mounted with initial endVal:', this.endVal);
    }
  };
</script>

<style scoped>
  .iCountUp {
    font-size: 3em;
    margin: 20px 0;
    color: #4d63bc;
    font-family: sans-serif;
  }
</style>

view raw JSON →