上传控件:

<el-upload class="upload-demo"  :on-change="filesChange">


filesChange方法:

filesChange(file, fileList) {
                if (file.size > 2000000) {
                    this.$message({
                        showClose: true,
                        message: "单个文件大小必须小于2Mb",
                        type: "warning"
                    });
                    var index = fileList.indexOf(file);
                    if (index > -1) {
                        fileList.splice(index, 1);
                    }
                }

                //判断文件名是否重复
                var count = 0
                var index = 0    // 记录要删除的文件下标               
                fileList.forEach((item, idx) => {
                    //在此处,对比文件名,将文件名相同的对比次数累加,
                    // 相同的文件名累加值为 2 时,说明文件名已经重复,直接删掉。
                    if (file.name == item.name) {
                        count++
                        if (count == 1) {
                            index = idx;
                        }
                        if (count === 2) {
                            this.$message({
                              message: file.name + '文件已存在',
                              type: 'info'
                            })              
                            fileList.splice(index, 1)
                        }
                    }
                })                
            },

 

相关文章:

  • 2021-09-23
  • 2021-07-26
  • 2021-11-29
  • 2021-12-13
  • 2021-07-14
  • 2021-12-30
  • 2021-04-06
  • 2022-12-23
猜你喜欢
  • 2021-10-19
  • 2022-01-21
  • 2022-01-09
  • 2021-09-13
  • 2021-12-21
  • 2021-12-13
  • 2022-12-23
相关资源
相似解决方案