<input
class="uni-input"
placeholder="请输入"
:maxlength="moneyMaxLeng"
type="text"
@input="oninput"
v-model="authData.companyInfo.income"
/>
oninput (e) {
this.$nextTick(() => {
let val = e.target.value.toString();
val = val.replace(/[^\d.]/g, ""); //清除"数字"和"."以外的字符
val = val.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
val = val.replace(/^0+\./g, '0.');
val = val.match(/^0+[1-9]+/) ? val = val.replace(/^0+/g, '') : val
val = (val.match(/^\d*(\.?\d{0,2})/g)[0]) || ''
if (val.includes(".")) {
let numDian = val.toString().split(".")[1].length;
// let numZheng = val.toString().split(".")[0].length;
if (numDian === 2) {
this.moneyMaxLeng = val.length;
}
} else {
this.moneyMaxLeng = 14;
}
let intPartFormat = val.toString().replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, "$&,") // 将整数部分逢三一断
this.authData.companyInfo.income = intPartFormat;
});
},