Vue converts input[type=number] to a string value

后端 未结 2 1788
春和景丽
春和景丽 2020-12-01 15:42

I\'m running into the problem, that Vue converts the value of an input field of type number into a string and I just can\'t figure out why. The guide I am following along do

相关标签:
2条回答
  • 2020-12-01 16:02

    Change the order object to :

    const order = {
        stockId: this.stock.id,
        stockPrice: this.stock.price,
        quantity: +this.quantity
    };
    

    This will automatically parse the string to a number.

    In general the data from HTML inputs are strings. The input type only checks if a valid string has been provided in the field.

    0 讨论(0)
  • 2020-12-01 16:06

    You need to use .number modifier for v-model, like this:

    <input v-model.number="quantity" type="number">
    
    0 讨论(0)
提交回复
热议问题