此处input的type 为digit
bash
<input v-model="amount" type="digit" placeholder="请填写金额" @input="checkAmount"/>
bash
data() {
return {
amount:""
}
}
bash
methods: {
// 小数点后2位
checkAmount(e){
e = (e.match(/^\d*(\.?\d{0,2})/g)[0]) || null
this.$nextTick(() => {
this.amount = e
})
},
}