elementui InputNumber 计数器
作者:互联网
需求: InputNumber 计数器 精度不固定,且小数点后不能去零。
目前没想到别的解决方法,仅想记录下补零过程。
<template v-if="fline.inputFormat == 3">
//<!-- 数字框 -->
<el-form-item
prop="fieldContent"
:rules="{
required: true, message: 'Please Enter1 ' + fline.fieldName, trigger: 'blur'
}">
<el-input-number
v-model="fline.fieldContent"
:precision="Number(fline.opts ? fline.opts[0].keep : fline.optionSelected[0].keep)"
:step="0.1"
:style="{'width': '100%'}" ></el-input-number>
</el-form-item>
</template>
if(i.inputFormat == 3){
// 数字框精度自动去0:补0
i.fieldContent = i.fieldContent == 0 ? '0.' : i.fieldContent
let valLang = i.fieldContent.toString().replace(/\d+\.(\d*)/,"$1").length // 小数点后面长度
let valBefor = i.fieldContent.toString().split('.')[0] // 小数点前面
let zero = '' // 补0初始化
let keep = i.opts ? i.opts[0].keep : i.optionSelected[0].keep
const stepLang = keep - valLang // 需要补几位
for(let i=0;i<stepLang;i++){
zero +='0'
}
let rep=/[\.]/
if(rep.test(i.fieldContent)){
i.fieldContent = i.fieldContent + zero
}else{
i.fieldContent = i.fieldContent + '.' + zero
}
let valLang2 = i.fieldContent.toString().replace(/\d+\.(\d*)/,"$1").length
if(valLang2 < keep){
i.fieldContent = i.fieldContent + '0'
}
}
标签:elementui,InputNumber,zero,keep,计数器,let,小数点,toString,fieldContent 来源: https://blog.csdn.net/qq_36533879/article/details/119207085