0๐
I hope this can help : v-mask package
- [Vuejs]-Add an undefined method promise to an array to be resolved later in Promise.all()
- [Vuejs]-My deployed Vue app works locally but not on remote server
0๐
You can use a computed
to format the displayed value in the input.
Vue.config.devtools = false;
Vue.config.productionTip = false;
var app = new Vue({
el: '#app',
data: {
rawSalary: 0
},
methods: {
onChange(e) {
this.rawSalary = e.target.value;
}
},
computed: {
formattedSalary() {
return this.rawSalary.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")
}
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<label>Salary</label>
<input type="text" :value="formattedSalary" @change="onChange">
<div>rawSalary : {{ rawSalary }}</div>
</div>
-1๐
You can use filter
to format the number into currency, for example:
filters: {
currencyFormat(val) {
return (val).toFixed(2)
.replace(/\d(?=(\d{3})+\.)/g, '$&,');
}
}
Use pipes to use it on your template, for example:
<div>
<input type="text" class="form-control" v-model="nasabah.form.salary | formatCurrency">
</div>
Please note that this will mutate your salary
property with the formatted value
You can learn more about it here
- [Vuejs]-Minimum moving parts needed to use VueJS components, preferably in ES5
- [Vuejs]-How to save axios request in vue.js store correclty?
Source:stackexchange.com