<el-upload
class="img"
action="#"
:show-file-list="false"
:http-request="Upload"
:before-upload="beforeImgUpload"
:on-change="handleChange"
>
<script setup>
//用来上传
let newFile = new FormData();
const handleChange = (file, fileList) => {
//如果第二次上传文件,将前一个文件删除
//这样fileList就一直保持一个文件
newFile.append("file", file.raw);
if (fileList.length > 1) {
fileList.splice(0, 1);
newFile.delete("file");
newFile.append("file", fileList[0].raw);
}
//给图片src赋值
imgUrl.value = URL.createObjectURL(file.raw);
};
</script>
el-upload实现 再次上传会覆盖前面的文件
最新推荐文章于 2024-07-30 15:32:11 发布