Closed sunmingtao closed 4 years ago
<div class="pull-left"> <input type="number" class="form-control" placeholder="Quality" v-model="quantity"> </div> <div class="pull-right"> <button class="btn btn-success" @click="buyStock" :disabled="quantity <= 0 || !Number.isInteger(quantity)">Buy</button> </div>
Number.isInteger(quantity) always evaluates to false, therefore, the button is always disabled.
Number.isInteger(quantity)
Turns out the variable quantity is a string. That's why it's never an integer. Fix 1: Change to !Number.isInteger(quantity * 1) Fix 2: v-model="quantity" changes to v-model.number="quantity"
!Number.isInteger(quantity * 1)
v-model="quantity"
v-model.number="quantity"
Number.isInteger(quantity)
always evaluates to false, therefore, the button is always disabled.