el-upload upload limit one file and override

When uploading a file, you can only upload the file and replace it, but you can set the limit to 1, but you can’t upload it repeatedly. You can only upload it again after deleting the original uploaded file.

 Set the limit to 2, and then delete the original file in the on-change event

<el-upload
    class="upload-demo"
    multiple
    :limit="2"
    :data="{type: 1}"
    accept=".doc, .docx, .zip, .rar"
    :action="uploadCover"
    :on-change="handleChangePic"
    :file-list="person_file_fileList"
    :headers="headersParams"
    :on-success="(value)=> handleAvatarSuccess('person_file', value)"
    :before-upload="beforeAvatarUpload">
    <div class="uoload-box">
        <el-button size="small" type="primary">点击上传</el-button>
        <div slot="tip" class="el-upload__tip">(文件支持格式为doc、docx、zip和rar,文件大小不能超过10M)</div>
    </div>
</el-upload>
handleChangePic(file,fileList) {
    if (fileList.length > 1) {
        fileList.splice(0, 1);
    }
},

 

 

Guess you like

Origin blog.csdn.net/weixin_48329823/article/details/130622912