<el-input v-model="input1" placeholder="请输入内容" @keyup.native="input1 = limitControlLine(input1,5,2)"></el-input>
limitControlLine (val,zs,xs) {
let value = val;
if (isNaN(val)) {
value = String(val).replace(/[^\d.]/g, '') // 清除“数字”和“.”以外的字符
value = value.replace(/\.{2,}/g, '.'); // 只保留第一个. 清除多余的
value = value.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.');
}
if (value.charAt(0) === '0' && val.charAt(1) !== '.') {
value = "0";
}
if (value.charAt(0) === '.') {
value = "0." + value.split('.')[1] ;
}
if (Number(value) >Math.pow(10,zs)) {
value = (value.split('.')[1] === undefined) ? value.substr(0,zs): value.substr(0,zs) + "." + value.split('.')[1];
}
if(value.indexOf('.')>0){
value=value.slice(0,value.indexOf('.')+ (xs + 1));
}
return value;
},