vue3+elementplus 完成excle 文件覆盖上传

vue3+elementplus 完成文件覆盖上传

前言,本人后端,小公司,前后端都要写,然后elementplus 的官网文档有没看懂,直接复制过来,各种报错,然后诞生这种奇怪的写法;
上代码
父页面:
     <suspense> //给子页面多包裹一层标签
           <v-handleadd ref="domadd" />  
   </suspense>
          const handleChange = (file, fileList) => {
           console.log("file---111111111", file.name);
           console.log("fileList--1-", fileList);

           if (file.name != fileList[0].name) {
               fileList.shift()
          }

           fileList = fileList.slice(-3);
      };

在 handleChange 文件改变的时候 ,把之前一个file给弹出去,这让就能实现覆盖上传了;对了,:limit要设置为2

                          <el-upload class="upload-demo" :action="fileDown" :on-change="handleChange"
                           :on-success="handleSuccess" :before-upload="beforeUpload" :on-progress="uploadProcess"
                           :file-list="fileList" :limit="2" :on-remove="handleRemove" :on-exceed="handleExceed">
                           <el-button type="primary">点击上传</el-button>
                       </el-upload>

 



posted @ 2022-06-20 16:52  Java不香吗  阅读(1293)  评论(0)    收藏  举报