This can be achieved by customizing the formatter function. Specific steps are as follows:
-
Add the :formatter attribute on <el-input-number>, with the value being the formatter function name.
-
Define the formatter function in methods, which receives a parameter value, which represents the value in the current input box.
-
In the formatter function, first convert the value into a string form, and then determine whether the length of the string is 1. If so, add a 0 in front of the string.
-
Finally, the processed string is returned.
Code example:
<el-input-number :formatter="formatNumber"></el-input-number>
methods: {
formatNumber(value) {
let str = value.toString()
if (str.length === 1) {
str = '0' + str
}
return str
}
}