保留两位小数
作者:互联网
HTML:
<div v-for="(item, index) in list" :key="index">
<input v-model="item.enable_amount" type="number" @input=" numberFixedDigit($event, item, 'enable_amount')"/>
</div>
data:
list: [ { enable_amount: null}, { enable_amount: null}, ],js:
numberFixedDigit(e, obj, name) { e.target.value = e.target.value.match(/^\d*(\.?\d{0,2})/g)[0] || ""; this.$nextTick(() => { obj[name] = Number(e.target.value) || null; }); },标签:两位,obj,target,保留,value,name,enable,null,小数 来源: https://www.cnblogs.com/gangshuai/p/15634325.html