金额最多只能输入两位小数
方法一:
<el-form-item label="金额" prop="dblamount">
<el-input v-model.trim="dialogForm.dblamount" type="number" placeholder="请输入" oninput="value=value.replace(/[^0-9.]/g,'').replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3').replace(/^0+(?=\d)/,'')" />
</el-form-item>
方法二:
<el-form-item label="金额" prop="dblamount">
<el-input
v-model.trim="dialogForm.dblamount"
type="number"
placeholder="请输入"
@input="upToTwoDecimal(dialogForm,'dblamount')"
/>
</el-form-item>
import { upToTwoDecimal } from '@/base/utils/decimal'
methods:{
upToTwoDecimal
}
decimal.js里面
export function upToTwoDecimal(row, prop) {
row[prop] = row[prop].replace(/[^\- \d.]/g, '')
if (row[prop].indexOf('.') > -1) {
row[prop] = row[prop].slice(0, row[prop].indexOf('.') + 3)
}
}