- 只能输入0-100的正整数
- 最小值~最大值联动
-
<el-input style="width: 70px" :formatter="formatInput" :parser="parseInput" @blur="checknum('min', inputData, 'value1', inputData.value2)" v-model.number="value" placeholder="最小值" /> ~~ <el-input style="width: 70px" :formatter="formatInput" :parser="parseInput" @blur="checknum('max', inputData, 'value2', inputData.value1)" v-model.number="value" placeholder="最大值" /> const formatInput = (value) => { // 格式化输入的值,保留数字部分 return value.replace(/^0+(\d)|[^\d]+/g, '') } const parseInput = (value) => { // 解析输入的值,将其转换为合法的数字 let numValue = parseInt(value, 10) if (isNaN(numValue)) return '' // 处理输入非数字的情况 // 限制输入的最小值和最大值 return Math.max(0, Math.min(100, numValue)).toString() } //最小值~最大值 const checknum = (type, inputData, field, otherValue) => { let numValue = parseInt(inputData[field], 10) || 0 if (type == 'max') { if (numValue < otherValue) { numValue = otherValue } } else { console.log(numValue, otherValue) if (otherValue != null && numValue > otherValue) { numValue = otherValue } } inputData[field] = numValue return numValue }
12-19
2045
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交