在这里插入图片描述
想不立即触发上传,又想校验文件
方法1:设置:auto-upload="false"后可以把校验写在on-change
方法2:使用 :http-request 存储文件,代码如下
<el-upload
:limit="1"
:file-list="fileList"
:http-request="requestUploadFile"
:on-exceed="handleExceed"
:before-upload="beforeUpload"
:on-error="handleError"
:before-remove="handleRemove"
>
<template #trigger>
<el-button type="primary" plain><el-icon class="el-icon--right"><Upload /></el-icon>上传</el-button>
</template>
</el-upload>
//把文件存到form里面
const requestUploadFile = (file) => {
console.log(file)
form.value.fileList.push(file.file)
}
const handleExceed = (files) => {
console.log('超出限制')
}
// 移除文件
const handleRemove = (uploadFile, uploadFiles) => {
}
//提交数据
const submitData = async(formEl: FormInstance | undefined ) => {
const uploadData = new FormData();
uploadData.append('file', form.value.fileList[0]);
uploadData.append('id',form.value.id);
console.log(uploadData)
}