我目前正在構(gòu)建一個(gè)文件上傳功能,可以在其中上傳一個(gè)或多個(gè) .xml 文件。 <button mat-raised-button class="button" (click)="fileInput.click()" <span>Choose files</span> <input #fileInput type="file" multiple accept=".xml" style="display:none;" (change)="onFileInput($event)"> </button>onFileInput 方法將這些文件推送到數(shù)組中。onFileInput($event) { Array.from($event.target.files).forEach(file => { this.files.push(file); }) this.files = [...new Set(this.files)];}問(wèn)題是,如果我更改上傳的文件數(shù)量,我可以多次上傳同一文件。案例1:上傳文件1,2上傳文件1,2this.files包含文件1,2到目前為止,一切都很好情況2:上傳文件1,2上傳文件1this.files 包含1,2,1上傳文件1this.files 仍包含1,2,1上傳文件2this.files 包含1,2,1,2我希望你能理解這個(gè)問(wèn)題并幫助我,因?yàn)槲艺也坏轿业腻e(cuò)誤。
刪除通過(guò) html 輸入上傳的重復(fù)文件不起作用
慕田峪4524236
2023-07-06 17:28:49