如何限制el-input 只能输入数字

vue2中的写法:

<input  type="number" step="1"  min="0" onkeyup="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''">

vue3中的写法:

<el-input v-model.number="itemForm.goodsNum" min="0" oninput="value=value.replace(/[^\d]/g,'')" placeholder="请输入物品数量"/>

如果你写了 type="number" 后面出现小箭头的话,可以通过样式去掉

::v-deep input::-webkit-outer-spin-button,
::v-deep input::-webkit-inner-spin-button {
    -webkit-appearance: none !important;
}
::v-deep input[type='number'] {
    -moz-appearance: textfield !important;
}

Guess you like

Origin blog.csdn.net/m0_58293192/article/details/129029215