A Vue.js component that wraps the awesome AutoNumeric input formatter library
vue-autoNumeric wraps the awesome AutoNumeric library and generate an
<input> element managed by AutoNumeric.
Checkout the demo!
Alternatively you can check the examples directly in your browser to see how to integrate the component with Vue and AutoNumeric.
yarn add vue-autonumeric# ornpm install vue-autonumeric --save
Note: In order to minimize the size of the vue-autoNumeric component, the AutoNumeric library dependency is not bundled with it.
This means you need to link the AutoNumeric library with either ways:
...in your html
<head> tag directly
<!-- locally... --><!-- ...or by using a CDN -->
Then you need to tell Webpack to treat the
AutoNumeric dependency as external so that it does not try to bundle it.
Here is a really simple
webpack.config.js example that does that:
moduleexports =entry : './src/vueAutonumericTest.js'output :filename: './dist/bundle.js'externals:autonumeric: 'AutoNumeric';
...or by importing it directly as an ES6 module
You can choose to directly import the AutoNumeric library in your source code.
First, install the
autonumeric dependency so that Webpack can find it using:
yarn add autonumeric# ornpm install autonumeric --save
You will as usual be able to use the
vue-autonumeric component in your Vue components using:
;name : 'myComponent'components:VueAutonumeric
However, when doing that if you want to be able to bundle all the scripts together with Webpack, you'll need to define an alias for the
AutoNumeric library in your Webpack config, otherwise Webpack will complain about the npm package
The alias that you need to declare in your Webpack configuration:
moduleexports =entry : './src/vueAutonumericTest.js'output :filename: './dist/bundle.js'resolve:alias:AutoNumeric: 'node_modules/autonumeric/dist/autoNumeric.min';
How to use?
The AutoNumeric component can be instantiated the same way
With an option object:
With a predefined option name:
With multiple option objects/predefined options:
You can define the input placeholder using:
You can also specify the type of html tag (within the AutoNumeric supported list) this component should generate using the
By default, an
<input> element is generated, but if you want a
<div> element, you can use:
Note: this will automatically set the
contenteditable attribute to
true for that generated element.
Integration with other scripts & events support
This wrapper supports setting the AutoNumeric options via an
It also supports external value changes (via
aNElement.set(42) for instance) and update the formatting and the
wheel events are supported as well.
Moreover, if you modify the
:options prop, the AutoNumeric settings will be automatically updated with the new options.
Please note that directly setting a
:value='42' on the
<vue-autonumeric> component will break it (really!).
Do NOT do that:
# this will build the component *and* the examplesyarn build
Then check the resulting html file in your browser using:
firefox ./examples/index.html # or `chrome`
This supports the same browsers than AutoNumeric supports:
- Firefox and
(latest 2 versions)
If you use IE/Edge/Safari/Opera, this might work ;)
Whenever you change the source code, you can check how it affects the default examples by first building those in
As always, if you find this useful, please consider supporting its development!
Huge Thanks :)
vue-autoNumeric is open-source and released under the MIT License.
Copyright © 2016-2018 Alexandre Bonneau
I would love to know how you're using vue-autonumeric.
Contact and tell me! :)