<el-input
v-model="strate.value"
@input.native="formatNum($event,index)"
>
formatNum(e, index) {
// 方法1
console.log(e, index)
console.log(e.target.value)
const pattern = /([1-9]+[\d]*(\.[0-9]{0,2})?)/
const match = e.target.value.match(pattern)
console.log(match)
if (match) {
e.target.value = e.target.value.replace(e.target.value, match[0])
} else {
e.target.value = ''
}
// 方法2
// e.target.value = e.target.value.replace(/(^\s*)|(\s*$)/g, '')
// const reg = /[^\d.]/g
// // 只能是数字和小数点,不能是其他输入
// e.target.value = e.target.value.replace(reg, '')
// // 保证第一位只能是数字,不能是点
// e.target.value = e.target.value.replace(/^\./g, '')
// // 小数只能出现1位
// e.target.value = e.target.value
// .replace('.', '$#$')
// .replace(/\./g, '')
// .replace('$#$', '.')
// // 小数点后面保留2位
// e.target.value = e.target.value.replace(
// /^(\-)*(\d+)\.(\d\d).*$/,
// '$1$2.$3'
// )
// 必须回显
this.form.strategies[index].value = e.target.value
}