html:

:formatter="numberRep " :parser="numberRep "
<a-row>
              <a-col :span="24">
                <a-form-model-item label="项目预警时间:">
                  <a-input-number v-model="bodyFrom.earlyWarningTime"
                                  :formatter="numberRep " :parser="numberRep " :min="0" class="b-margin" style="width: 92%" />分钟
                </a-form-model-item>
              </a-col>
            </a-row>
/* 只能输入整数 */
numberRep = (value: string | number) => {
  if (typeof value === 'string') {
    return !isNaN(Number(value)) ? value.replace(/^(0+)|[^\d]/g, '') : ''
  } else if (typeof value === 'number') {
    return !isNaN(value) ? String(value).replace(/^(0+)|[^\d]/g, '') : ''
  } else {
    return ''
  }
}
Logo

前往低代码交流专区

更多推荐