How to make v-money recognize zeros after the comma

Asked

Viewed 782 times

-1

I’m using v-money for prices, if in the database there is no 0 at the end as for example: 10.99, when searching the value and playing in the input, the value appears normally. Now if in the database the value is 10.00, in the input appears 0.10. The API returns the 10.00 without the comma and the zeros (10), ai the v-money understands as 0.10.

NOTE: I am using v-money as a directive.

How do I solve this problem?

<input class="form-control" id="produto-precoCusto" v-model="produto.precoCusto" v-money="money" v-model.lazy="produto.precoCusto"/>

data: function() {
return {
  money: {
    decimal: ",",
    thousands: "",
    precision: 2,
    masked: false
  },},}

1 answer

0

Try to make it equal:

new Vue({
  el: '#app',
  data() {
    return {
      price: '123,50',
      money: {
        decimal: ',',
        thousands: ',',
        prefix: 'R$ ',
        suffix: ' #',
        precision: 2,
        masked: false /* doesn't work with directive */
      }
    }
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/spectre.css/0.2.14/spectre.min.css" rel="stylesheet" />
<script src="https://rawgit.com/vuejs-tips/v-money/master/dist/v-money.js"></script>

<div id="app" class="empty">
  <h1>
    Directive
  </h1>
  <input v-model="price" v-money="money" class="form-input input-lg" style="text-align: right" /> {{price}}
</div>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.