kevinongko/vue-numeric

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

npmnpmnpmNode.js CICodecovnpm

Input field component to display a formatted currency value based on Vue.

Live Demo

Works with Vue 2.*

<script src="https://unpkg.com/accounting-js"></script>
<script src="https://unpkg.com/vue"></script>
<script src="https://unpkg.com/vue-numeric"></script>

<script>
  Vue.use(VueNumeric.default)
</script>
$ npm install vue-numeric --save
import Vue from 'vue'
import VueNumeric from 'vue-numeric'

export default {
  name: 'App',

  components: {
    VueNumeric
  }
}
import Vue from 'vue'
import VueNumeric from 'vue-numeric'

Vue.use(VueNumeric)

screen shot 2016-12-08 at 2 19 31 pm

<template>
  <vue-numeric currency="$" separator="," v-model="price"></vue-numeric>
</template>

<script>
import VueNumeric from 'vue-numeric'

export default {
  name: 'App',

  components: {
    VueNumeric
  },

  data: () => ({
    price: ''
  }),
}
</script>

Set the currency prop to add a currency symbol within the input.

<vue-numeric currency="$"></vue-numeric>

Limit the minimum and maximum value by using min and max props.

  • min defaults to 0.
  • min and max accept String or Number values.
<vue-numeric v-bind:min="2000" v-bind:max="10000"></vue-numeric>

minus defaults to false (no negative numbers).

<vue-numeric v-bind:minus="false"></vue-numeric>

By default the decimal value is disabled. To use decimals in the value, add the precision prop.

  • precision accept a String or Number numeric value.
<vue-numeric v-bind:precision="2"></vue-numeric>
  • Default thousand separator's symbol is ,.
  • Use the separator prop to change the thousands separator.
  • separator only accepts space, , or ..
  • When using the . or space as thousand separator, the decimal separator will be ,.
<vue-numeric separator="."></vue-numeric>
<vue-numeric placeholder="only number allowed"></vue-numeric>

By default, when you clean the input the value is set to 0. You can change this value to fit your needs.

<vue-numeric :empty-value="1"></vue-numeric>

By default the value emitted for the input event is of type Number. However you may choose to get a String instead by setting the property output-type to String.

<vue-numeric output-type="String"></vue-numeric>
PropsDescriptionRequiredTypeDefault
currencyCurrency prefixfalseString-
currency-symbol-positionPosition of the symbol (accepted values: prefix or suffix)falseStringprefix
maxMaximum value allowedfalseNumber9007199254740991
minMinimum value allowedfalseNumber-9007199254740991
minusEnable/disable negative valuesfalseBooleanfalse
placeholderInput placeholderfalseString-
empty-valueValue when input is emptyfalseNumber0
output-typeOutput Type for input eventfalseStringNumber
precisionNumber of decimalsfalseNumber-
separatorThousand separator symbol (accepts space, . or ,)falseString,
decimal-separatorCustom decimal separatorfalseString-
thousand-separatorCustom thousand separatorfalseString-
read-onlyHide input field and show the value as textfalseBooleanfalse
read-only-classClass for read-only elementfalseString''
allow-clearUse input type searchfalseBooleanfalse

Vue-Numeric is open-sourced software licensed under the MIT license

Hello, I'm Kevin the maintainer of this project in my free time (which is getting lessen these days), if this project does help you in any way please consider to support me. Thanks 😃

About

Input field component to display a formatted currency value based on Vue.js

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 17