Antd InputNumber (7.1.4v) 不允许输入 0

Antd InputNumber (7.1.4v) not allowing to enter 0

我需要对 InputNumber 进行字段验证。但是如果我们输入 0,它会被转换为空并引发验证错误。请告诉我如何避免这种情况

您可以查看以下 InputNumber 示例(有效)

import React from 'react';
import 'antd/dist/antd.css';
import { Form, InputNumber, Button } from 'antd';

const Demo = () => {
  const onFinish = (values) => {
  console.log('Success:', values);
 };

const onFinishFailed = (errorInfo) => {
  console.log('Failed:', errorInfo);
};

return (
 <Form
   onFinish={onFinish}
   onFinishFailed={onFinishFailed}
   autoComplete="off"
 >
  <Form.Item
    label="Number"
    name="number"
    rules={[
      {
        required: true,
        message: 'Please enter your number!',
      },
    ]}
  >
    <InputNumber />
  </Form.Item>

  <Form.Item>
    <Button type="primary" htmlType="submit">
      Submit
    </Button>
  </Form.Item>
</Form>
);
}

export default Demo;

您也可以使用最小值和最大值

    <InputNumber min={1} max={10} defaultValue={5} />