Vue Numeric Input Field

2.5.1 · active · verified Sun Apr 19

Vue Numeric is a lightweight input component for Vue.js 2, designed to format and handle numeric values, particularly useful for currency inputs. The library is currently at version 2.5.1 and maintains an active release cadence, primarily focusing on bug fixes and minor feature enhancements. Key functionalities include automatic formatting with currency symbols, customizable thousands and decimal separators, precision control, and defining minimum/maximum constraints. It also offers control over the output type (Number or String) and the value used when the input is empty. Unlike simple HTML input types, vue-numeric provides robust, localized formatting and validation suitable for financial or data entry applications exclusively within Vue 2 ecosystems.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates importing and globally registering `vue-numeric` as a Vue plugin, then using the component with various props like currency symbol, precision, separators, and min/max constraints, along with `v-model` binding for both Number and String output types.

<template>
  <div id="app">
    <h1>Vue Numeric Demo</h1>
    <p>Price: <vue-numeric currency="$" separator="," v-model="price" :precision="2" :min="0"></vue-numeric></p>
    <p>Value: {{ price }} (Type: {{ typeof price }})</p>

    <p>Quantity: <vue-numeric :output-type="'String'" :precision="0" v-model="quantity"></vue-numeric></p>
    <p>Value: {{ quantity }} (Type: {{ typeof quantity }})</p>

    <p>Discount: <vue-numeric currency="€" currency-symbol-position="suffix" separator="." :precision="2" :min="-100" :max="0" v-model="discount"></vue-numeric></p>
    <p>Value: {{ discount }} (Type: {{ typeof discount }})</p>
  </div>
</template>

<script>
import Vue from 'vue';
import VueNumeric from 'vue-numeric';

Vue.use(VueNumeric); // Register as a global component

export default {
  name: 'App',
  data() {
    return {
      price: 1234.56,
      quantity: '1000',
      discount: -50.00
    };
  },
  // If not registered globally via Vue.use(), register as local component:
  // components: {
  //   VueNumeric
  // }
};
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
input {
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 1em;
  width: 200px;
}
</style>

view raw JSON →