mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 07:49:20 +08:00
fix(profile): 修复头像预览 - 改用 @change 替代 before-upload
before-upload 的 async 返回值处理在某些场景下不生效,改为 @change 事件直接处理
This commit is contained in:
@@ -61,22 +61,22 @@ async function fetchUserInfo() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleAvatarChange(info: any) {
|
function handleAvatarChange({ file }: { file: any }) {
|
||||||
const file = info.file.originFileObj || info.file;
|
// 获取实际文件对象
|
||||||
if (!file) return false;
|
const actualFile = file.originFileObj || file;
|
||||||
|
if (!actualFile) return;
|
||||||
|
|
||||||
if (!file.type.startsWith('image/')) {
|
if (!actualFile.type.startsWith('image/')) {
|
||||||
message.error('只能上传图片文件');
|
message.error('只能上传图片文件');
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
if (file.size > 2 * 1024 * 1024) {
|
if (actualFile.size > 2 * 1024 * 1024) {
|
||||||
message.error('图片大小不能超过 2MB');
|
message.error('图片大小不能超过 2MB');
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 缓存头像文件,预览由 computed avatarSrc 自动处理
|
// 缓存头像文件,预览由 computed avatarSrc 自动处理
|
||||||
pendingAvatarFile.value = file;
|
pendingAvatarFile.value = actualFile;
|
||||||
return false; // 阻止默认上传
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleSubmit() {
|
async function handleSubmit() {
|
||||||
@@ -153,7 +153,7 @@ fetchUserInfo();
|
|||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
<div class="mr-6">
|
<div class="mr-6">
|
||||||
<Upload
|
<Upload
|
||||||
:before-upload="handleAvatarChange"
|
@change="handleAvatarChange"
|
||||||
:show-upload-list="false"
|
:show-upload-list="false"
|
||||||
accept="image/*"
|
accept="image/*"
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user