Animated Number Vue
This package, `animated-number-vue` (version 1.0.0), provides a Vue 2 component designed to animate numerical values. It leverages the `animejs` library for its animation engine, offering smooth transitions for displaying numbers like prices, scores, or counts. Key features include configurable animation duration, delay, easing functions, and a `formatValue` prop for custom output formatting (e.g., currency, percentages). It also exposes callback props (`update`, `run`, `begin`, `complete`) for reacting to different stages of the animation lifecycle. Its primary differentiator is its simplicity and direct integration with Vue 2 projects, specifically using `animejs` for animation control. Given its explicit targeting of Vue 2, it is considered to be in a maintenance state, without active development or official support for Vue 3 or newer versions of the framework.
Common errors
-
[Vue warn]: Failed to resolve component: animated-number
cause The component is not properly registered in a Vue 2 application, or you are attempting to use it in a Vue 3 project.fixEnsure `AnimatedNumber` is imported and registered locally within your component's `components` option, or globally via `Vue.component('animated-number', AnimatedNumber);` if using Vue 2. If in Vue 3, this package is incompatible. -
TypeError: AnimatedNumber is not a constructor (or similar CJS/ESM import error)
cause Attempting to import the component using CommonJS `require()` syntax in an environment expecting ES modules, or vice-versa.fixAlways use `import AnimatedNumber from 'animated-number-vue';` within Vue Single File Components or JavaScript modules. Avoid `const AnimatedNumber = require('animated-number-vue');`.
Warnings
- breaking This package is explicitly built for Vue 2. It is not compatible with Vue 3 or later versions of the framework.
- gotcha The `value` prop accepts both Number and String types. However, numerical operations within the `formatValue` callback (like `toFixed`) will require the value to be a Number, so ensure type consistency or handle string parsing.
- deprecated The underlying `animejs` library might have updated its easing function names or availability since this package's last update. Consult `animejs` documentation for the latest valid easing values.
Install
-
npm install animated-number-vue -
yarn add animated-number-vue -
pnpm add animated-number-vue
Imports
- AnimatedNumber
const AnimatedNumber = require('animated-number-vue');import AnimatedNumber from 'animated-number-vue';
- AnimatedNumber (named import)
import { AnimatedNumber } from 'animated-number-vue';import AnimatedNumber from 'animated-number-vue';
- Vue plugin registration
import AnimatedNumber from 'animated-number-vue'; Vue.component('animated-number', AnimatedNumber);
Quickstart
<template>
<animated-number
:value="value"
:formatValue="formatToPrice"
:duration="300"
/>
</template>
<script>
import AnimatedNumber from "animated-number-vue";
export default {
components: {
AnimatedNumber
},
data() {
return {
value: 1000
};
},
methods: {
formatToPrice(value) {
return `R$ ${value.toFixed(2)}`;
}
}
};
</script>