<el-input v-model="balanceRechargePrices" placeholder="请输入充值金额" @input="handleInput" @focus="focusInput"></el-input>
const handleInput = (value: string) => {
console.log('value', value);
const restrictedValue = value.replace(/[^0-9.]/g, '').replace(/^./, '');
// 限制小数点后最多两位
let limitedValue = restrictedValue.split('.').length > 1 ? ${restrictedValue.slice(0, restrictedValue.indexOf('.') + 3)}
: restrictedValue;
limitedValue = limitedValue.replace(/(..*)./g, '$1');
balanceRechargePrice.value = limitedValue ? limitedValue : 0;
balanceRechargePrices.value = limitedValue ? limitedValue : '';
};
const focusInput = () => {
balanceRechargePrice.value = balanceRechargePrices.value;
};
网友评论