代码:
import { Button, UploadProps, Upload, message } from 'antd';
import { UploadOutlined } from '@ant-design/icons';
const MyUpload: React.FC = () => {
const props: UploadProps = {
name: 'jpgFile',
action: '/xxxxx/xx/接口',
headers: {
authorization: 'token',
},
showUploadList: false,
maxCount: 1,
accept: '.jpg',
onChange(info) {
if (info.file.status === 'done') {
//上传成功之后的操作
} else if (info.file.status === 'error') {
message.error('file upload failed.');
}
},
};
return (
<>
<Upload {...props}>
<Button icon={<UploadOutlined />}>Click to Upload</Button>
</Upload>
</>
);
};
export default MyUpload;
效果图:
antd 上传(Upload):
上传 Upload - Ant Design