import React, { useState } from 'react';
import { Avatar } from 'antd';
import { UploadOutlined } from '@ant-design/icons';
const AvatarUpload = () => {
const [avatarUrl, setAvatarUrl] = useState('');
const handleChangeUploadAvatar = (info: any) => { // 这里传入any类型,原因是ant-design组件Upload返回的info类型中有许多值class,无法具体定义
if (info.file.status === 'done') {
setAvatarUrl(info.file.response);
}
}
const customRequestUploadAvatar = (options: any) => { // 这里传入any类型,同上
const data = new FormData();
data.append('avatar', options.file);
axios.post('/api/avatar', data).then((response) => {
options.onSuccess(response.data, options.file);
});
}
return (
}>Upload
);
};
export default AvatarUpload;
注意:如果您仍然无法解决此问题,则需要提供更多信息,例如完整的TypeScript错误日志以及您的上传代码。