antd清除select选中的值
时间: 2023-06-06 18:07:51 浏览: 194
对于您的问题,您可以使用Antd的resetFields方法来清除select选中的值。
示例代码:
```javascript
import { Form, Select, Button } from 'antd';
const { Option } = Select;
const Demo = () => {
const [form] = Form.useForm();
const onFinish = (values) => {
console.log(values);
};
const onReset = () => {
form.resetFields(); // 清除选中的值
};
return (
<Form form={form} onFinish={onFinish}>
<Form.Item name="select" label="Select" rules={[{ required: true }]}>
<Select placeholder="Select a option and change input text above" allowClear>
<Option value="option1">Option1</Option>
<Option value="option2">Option2</Option>
<Option value="option3">Option3</Option>
</Select>
</Form.Item>
<Form.Item>
<Button type="primary" htmlType="submit">
Submit
</Button>
<Button htmlType="button" onClick={onReset}>
Reset
</Button>
</Form.Item>
</Form>
);
};
export default Demo;
```
阅读全文