<el-input-number> displays two digits; if it is one digit, add 0 in front

This can be achieved by customizing the formatter function. Specific steps are as follows:

  1. Add the :formatter attribute on <el-input-number>, with the value being the formatter function name.

  2. Define the formatter function in methods, which receives a parameter value, which represents the value in the current input box.

  3. 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.

  4. 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
  }
}

Guess you like

Origin blog.csdn.net/u012632105/article/details/132773058