element 上传文件 文件列表只显示最新的一条

上传操作 :

      <el-upload
        multiple
        accept=".rar,.zip,.doc,.pdf,.docx"
        class="upload-demo"
        thumbnail-mode
        :on-change="handleChange"
        action
        :file-list="fileList"
        :show-file-list="true"
        :http-request="uploadfile"
        >
        <el-button size="small" type="primary" class="upload">上传审稿模板</el-button>
<!--        <div slot="tip" class="el-upload__tip">支持格式:.rar .zip .doc .docx .pdf,单个文件不能超过20MB。</div>-->
      </el-upload>

上传函数:

// 上传附件
      uploadfile(file){
        let formData = new FormData()
        formData.append("file", file.file)
//
updatetemplate 是接口
updatetemplate(formData).then( res => { if(res.data.code == 0){ this.$message.success("上传成功") } }) },

上传函数时列表操作 :删除掉之前的

   handleChange(file, fileList) {
        this.fileList = fileList.slice(-1);
      },
原文地址:https://www.cnblogs.com/guangzhou11/p/13959512.html