[Vuejs]-Round up a number in the v-model in vuejs

2👍

Maybe you can try to use a computed property in v-model instead of an expression.

<b-form-input id="amount_input" type="number"
     v-model="reward_cents"
      :state="reward_cents"/>

<script>
  export default {
    computed: {
      reward_cents: {
        get() {
          return this.form.contract.reward_cents;
        },
        set(val) {
          this.form.contract.reward_cents = Math.ceil(val / 100);
        }
      }
    }
  }
</script>

1👍

you can follow:

<b-form-input 
id="amount_input" 
type="number"
:value="form.contract.reward_cents"
v-model="reward_cents"
@change="OnChange"
:state="validate(form.contract.reward_cents)"/>

data(){
    return: {
        reward_cents: 0
    }
}

methods: {
    OnChange(newVal){
        this.reward_cents = Math.ceil(newVal / 100);
    }
}

Leave a comment