The elementui el-input component is limited to only input numbers and the decimal point is 3 digits, only one decimal point, and if the beginning of 0 is not followed by a decimal point, it will be replaced with a number and automatically completed

The code is implemented as follows:

<el-input
  v-model="scope.row.num"
  size="mini"
  oninput="
      this.value=this.value.replace(/\D*(\d*)(\.?)(\d{0,3})\d*/,'$1$2$3') // 只能输入数字、小数点限制3位
     .replace(/^0+(\d)/, '$1') // 第一位0开头,0后面为数字,则过滤掉,取后面的数字
     .replace(/^\./, '0.')  // 如果输入的第一位为小数点,则替换成 0. 实现自动补全
     .match(/^\d*(\.?\d{0,3})/g)[0] || '' // 数字开头、小数点3位
   "
/>

Guess you like

Origin blog.csdn.net/DarlingYL/article/details/125875098