Vue uses el-upload to upload files. We tried to use the built-in parameter :limit=1, but the interaction effect is not good. Objective: Only one file is allowed to be uploaded. In the case of multiple uploads, the last one overwrites the first one
// Do not use limit <el-form> <el-form> <el-upload v-show="radio1 == 2" action="" :on-change="handleFileChange" :before-remove="beforeFileRemove" :on-remove="handleFileRemove" :file-list="File" :auto-upload="false" > <el-button Size ="small" type="primary"> </el-button> <span slot="tip" class="el-upload__tip"> </el-form-item> </el-form>Copy the code
/ / JS code
HandleFileChange (file, fileList) {// this.checkfile checkFile format and size if (this.checkfile (file)) {// if filelist.length >1. If (filelist.length > 1) {filelist.splice (0, 1); this.File = []; } this.File.push(fileList[0].raw); } else {// Check not pass, clear the bound File this.file = []; }},Copy the code