// 事件兩個參數,參數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 時,文件進行替換。