最近项目中遇到个新需求,添加附件时要支持附件的批量上传。目前项目中附件上传是一个一个上传,图片和其他类型的文件分别上传到不同的服务。原本想是直接加上:multiple="true"
就完事,事实并不如此,先看下代码:
<el-upload
ref="upload"
:multiple="true"
:action="uploadAction"
:accept="acceptUpload"
:auto-upload="true"
:show-file-list="false"
:disabled="uploadLoading"
:before-upload="onUploadChange"
:on-success="handleUploadSuccess"
>
<el-button :loading="uploadLoading" :disabled="uploadLoading" icon="el-icon-plus" type="default" plain>
{
{
uploadLoading ? '正在上传...' : '上传附件' }}
</el-button>
</el-upload>
// ...
methods: {
// ...
// 上传前根据不同文件类型上传到不同服务
onUploadChange(file) {
if (file.size && file.size / 1024 / 1024 > maxUploadSize) {
this.$notify({
type: 'error',
title: `上传附件大小不能超过${
maxUploadSize}MB`,
});
return false;
}
console.log('%c [onUploadChange]: ', 'color:#1989fa;', file);
// return true;
return new Promise((resolve, reject) => {