Reputation: 127
I can get salary data from my database using vue js like this
but I want to add curency code like this but I don't know how to do it
here is my code for my retrieve, the field key salary is a double how to add " Rp. " in a input with vue js ??
<div class="form-row">
<div class="form-group col-md-6">
<label class="col-form-label">Salary</label>
<input type="text" class="form-control" v-model="nasabah.form.salary">
</div>
</div>
Upvotes: 0
Views: 1471
Reputation: 1432
You have to use the value
attribute instead of v-model
. Then, I would advice you to make the input field readonly
to prevent any unexpected behaviour that will arise when someone changes the value.
data() {
return {
nasabah: {
form: {
salary: ''
}
}
}
}
<div class="form-row">
<div class="form-group col-md-6">
<input
:value="formattedSalaryWithCurrency"> //use the value attribute
readonly // make it readonly to prevent unexpected behaviour
>
</div>
</div>
computed: { // a computed property will only re-compute when a dependency changes (in this case, this.nasabah.form.salary;)
formattedSalaryWithCurrency() {
return this.formatSalaryWithCurrency(this.nasabah.form.salary);
}
}
methods: {
formatSalaryWithCurrency(amount) {
`Rp.${amount}`
}
}
Upvotes: 2