// 事件两个参数,参数file与fileList是同时有值的。 onChangeUpload(file, fileList) { var a = 0 fileList.forEach((item, idx) => { //在此处,对比文件名,将文件名相同的对比次数累加, // 相同的文件名累加值为 2 时,说明文件名已经重复,直接删掉。 if (file.name === item.name) { a++ if (a === 2) { this.$message({ message: ‘文件名不能重复‘, type: ‘info‘ }) fileList.splice(idx, 1) } } }) }
此方法为附件去重。
如要相同附件覆盖已上传的,只需在 a === 1 时,保留对应下标;当 a === 2 时,文件进行替换。
原文:https://www.cnblogs.com/anbozhu7/p/10431786.html