Last active: 2 years ago
Open file upload when click any element
const handleAvatar = useCallback(() => {
if (avatarLoading) return;
const input = document.createElement('input');
input.type = 'file';
input.accept = 'image/*';
input.click();
const form = new FormData();
input.addEventListener('change', async (e) => {
if (!input.files?.length) return;
form.append('headimg', input.files[0]);
setLoad();
try {
const result = await editUserInfo(form);
message.success(result);
} catch (e) {
console.log(e);
message.warn('请求失败');
} finally {
getUser();
noLoad();
}
});
}, []);