If you are using Vuetify, a new light-weight library called 'vuetify-money' has been published. Super easy to use for money value inputs, it is a text field that will add commas as you type. Here's a demo.
All properties you use on a v-text-field can also be used, so it is easily customizable.
Step 1
npm install vuetify-money --save
Step 2
Create a src/plugins/vuetify-money.js file with the following content:
import Vue from "vue";
import VuetifyMoney from "vuetify-money";
Vue.use(VuetifyMoney);
export default VuetifyMoney;
Step 3
Add file to src/main.js :
import "./plugins/vuetify-money.js";
(main.js is the file where you usually put this)
new Vue({render: h => h(App)
}).$mount('#app');
Step 4
Use it in your code !
<template>
<div>
<vuetify-money
v-model="value"
v-bind:options="options"
/>
Parent v-model: {{ value }}
</div>
</template>
<script>
export default {
data: () => ({
value: "1234567.89",
options: {
locale: "ja-JP",
prefix: "$",
suffix: "",
length: 10,
precision: 2
}
})
};
</script>
You now have a text field that will add commas as you type while keeping the v-model values perfectly fine. It also prevents any non-number inputs so you hardly need front-end validation checks excluding customized cases.