【问题标题】:How do I remove a file from the FileList如何从 FileList 中删除文件
【发布时间】:2011-03-09 20:02:25
【问题描述】:

我正在使用 HTML5 构建一个拖放上传 Web 应用程序,我将文件拖放到一个 div 上,当然还获取了 dataTransfer 对象,这给了我FileList

现在我想删除一些文件,但我不知道如何,或者是否可能。

最好我想从 FileList 中删除它们;我对他们没有用。但如果这不可能,我是否应该在与 FileList 交互的代码中写入检查?这似乎很麻烦。

【问题讨论】:

  • 只是好奇:你为什么要这样做?为什么你对用户选择的(一些)文件说“我对他们没有用”?
  • 这可能更多是为了让用户可以在上传之前删除文件。如果您最初选择了 20 个,然后您决定实际上不想上传第 14 个,那么您不能只删除那个,您必须重新开始(这有点痛苦)。我认为将 FileList 设为只读是一个糟糕的疏忽,除非有一些我没有看到的安全隐患。
  • 直接从输入的 FileList 中删除文件存在安全问题,但您可以在关闭文件上传对话框后立即克隆该 FileList,然后修改此克隆并在通过 ajax 发布时使用它

标签: javascript html drag-and-drop filelist


【解决方案1】:

如果您只想删除几个选定的文件:您不能。您链接到的File API Working Draft 包含一条注释:

HTMLInputElement 接口 [HTML5] 有一个只读 FileList 属性,[…]
[强调我的]

阅读了一些 HTML 5 工作草案,我发现了Common input element APIs。看来您可以通过将input 对象的value 属性设置为空字符串来删除整个 文件列表,例如:

document.getElementById('multifile').value = "";

顺便说一句,Using files from web applications 的文章可能也很有趣。

【讨论】:

  • 请注意,只读属性not意味着您不能更改它指向的对象。您可以操纵 FileList(如果可能的话),这只是意味着您不能为其分配新的 FileList。
  • @RobinBerjon Chrome 似乎忽略了“只读”属性,而 FireFox 不允许写入操作。不幸的是,您仅操纵 FileList 的建议在 FireFox 中也不起作用。
  • 我认为只有length 是只读的。我尝试使用拼接删除一个项目,它在 Chrome 中失败。
  • 有没有办法添加?
  • @streetlight 这将是一个巨大的安全漏洞,如果网站所有者可以确定从用户的机器上传哪些文件。
【解决方案2】:

此问题已被标记为已回答,但我想分享一些可能有助于其他人使用 FileList 的信息。

将 FileList 视为数组会很方便,但 sort、shift、pop 和 slice 等方法不起作用。正如其他人所建议的,您可以将 FileList 复制到数组中。但是,不是使用循环,而是有一个简单的单行解决方案来处理这种转换。

 // fileDialog.files is a FileList 

 var fileBuffer=[];

 // append the file list to an array
 Array.prototype.push.apply( fileBuffer, fileDialog.files ); // <-- here

 // And now you may manipulated the result as required

 // shift an item off the array
 var file = fileBuffer.shift(0,1);  // <-- works as expected
 console.info( file.name + ", " + file.size + ", " + file.type );

 // sort files by size
 fileBuffer.sort(function(a,b) {
    return a.size > b.size ? 1 : a.size < b.size ? -1 : 0;
 });

在 FF、Chrome 和 IE10+ 中测试正常

【讨论】:

  • Array.from(fileDialog.files) 更简单
  • @Muhammad Umer - 谢谢,我同意它更简单,它被列为替代答案。然而,这取决于必须支持哪些浏览器,以及它们是否需要 pollyfill 才能使用 Array.from()。见:stackoverflow.com/a/36810954/943435
  • 如何实际修改 FileList?将此新数组分配给输入 fileDialog.files = fileBuffer ?
  • @3zzy - 可以修改 FileList,但仅限于现代浏览器。有关详细信息,请参阅此 SO 问题:stackoverflow.com/a/47522812/943435
  • 是 shift() 还是 splice() ?我认为应该是后者。
【解决方案3】:

如果您的目标是常青浏览器(Chrome、Firefox、Edge,但也适用于 Safari 9+)或者您可以负担得起 polyfill,您可以使用 Array.from() 将 FileList 转换为数组,如下所示:

let fileArray = Array.from(fileList);

然后像处理任何其他数组一样轻松处理Files 数组。

【讨论】:

  • 完美!你知道IE支持怎么样?或者你可以分享一个 polyfill 的链接?
  • 我没试过,但这是谷歌的第一个结果;)github.com/mathiasbynens/Array.from
  • 它只允许你处理fileArray 而不是fileList
【解决方案4】:

由于 JavaScript FileList 是只读的,不能直接操作,

最佳方法

您必须遍历input.files,同时将其与您要删除的文件的index 进行比较。同时,您将使用new DataTransfer() 设置一个新的文件列表,不包括您要从文件列表中删除的文件。

通过这种方法,input.files 本身的值发生了变化。

removeFileFromFileList(index) {
  const dt = new DataTransfer()
  const input = document.getElementById('files')
  const { files } = input
  
  for (let i = 0; i < files.length; i++) {
    const file = files[i]
    if (index !== i)
      dt.items.add(file) // here you exclude the file. thus removing it.
  }
  
  input.files = dt.files // Assign the updates list
}

替代方法

另一个简单的方法是将FileList转换成数组,然后拼接。

但是这种方法不会改变input.files

const input = document.getElementById('files')
// as an array, u have more freedom to transform the file list using array functions.
const fileListArr = Array.from(input.files)
fileListArr.splice(index, 1) // here u remove the file
console.log(fileListArr)

【讨论】:

  • 非常感谢您,但是请注意,除非您从列表末尾删除文件,否则在某些时候不会删除任何内容,因为索引在每个循环中都会被重置,因此要获得周围最好使用这个技巧geeksforgeeks.org/how-to-get-the-child-node-index-in-javascript
  • @ct0 这就是为什么你应该反向循环。从后面到数组的开头。所以你永远不会弄乱索引。
【解决方案5】:

由于我们处于 HTML5 领域,这是我的解决方案。要点是您将文件推送到数组而不是将它们留在 FileList 中,然后使用 XHR2,将文件推送到 FormData 对象。下面的例子。

Node.prototype.replaceWith = function(node)
{
    this.parentNode.replaceChild(node, this);
};
if(window.File && window.FileList)
{
    var topicForm = document.getElementById("yourForm");
    topicForm.fileZone = document.getElementById("fileDropZoneElement");
    topicForm.fileZone.files = new Array();
    topicForm.fileZone.inputWindow = document.createElement("input");
    topicForm.fileZone.inputWindow.setAttribute("type", "file");
    topicForm.fileZone.inputWindow.setAttribute("multiple", "multiple");
    topicForm.onsubmit = function(event)
    {
        var request = new XMLHttpRequest();
        if(request.upload)
        {
            event.preventDefault();
            topicForm.ajax.value = "true";
            request.upload.onprogress = function(event)
            {
                var progress = event.loaded.toString() + " bytes transfered.";
                if(event.lengthComputable)
                progress = Math.round(event.loaded / event.total * 100).toString() + "%";
                topicForm.fileZone.innerHTML = progress.toString();
            };
            request.onload = function(event)
            {
                response = JSON.parse(request.responseText);
                // Handle the response here.
            };
            request.open(topicForm.method, topicForm.getAttribute("action"), true);
            var data = new FormData(topicForm);
            for(var i = 0, file; file = topicForm.fileZone.files[i]; i++)
                data.append("file" + i.toString(), file);
            request.send(data);
        }
    };
    topicForm.fileZone.firstChild.replaceWith(document.createTextNode("Drop files or click here."));
    var handleFiles = function(files)
    {
        for(var i = 0, file; file = files[i]; i++)
            topicForm.fileZone.files.push(file);
    };
    topicForm.fileZone.ondrop = function(event)
    {
        event.stopPropagation();
        event.preventDefault();
        handleFiles(event.dataTransfer.files);
    };
    topicForm.fileZone.inputWindow.onchange = function(event)
    {
        handleFiles(topicForm.fileZone.inputWindow.files);
    };
    topicForm.fileZone.ondragover = function(event)
    {
        event.stopPropagation();
        event.preventDefault();
    };
    topicForm.fileZone.onclick = function()
    {
        topicForm.fileZone.inputWindow.focus();
        topicForm.fileZone.inputWindow.click();
    };
}
else
    topicForm.fileZone.firstChild.replaceWith(document.createTextNode("It's time to update your browser."));

【讨论】:

  • ajax 是我猜的唯一方法?
【解决方案6】:

我为此找到了非常快速且简短的解决方法。在许多流行的浏览器(Chrome、Firefox、Safari)中测试;

首先,您必须将 FileList 转换为数组

var newFileList = Array.from(event.target.files);

要删除特定元素,请使用 this

newFileList.splice(index,1);

【讨论】:

  • 您从 event.target.files 创建了新变量,该变量未链接到输入,因此除了您的局部变量之外它无法更改任何内容..
【解决方案7】:

我知道这是一个老问题,但它在搜索引擎上的排名很高。

FileList 对象中的属性无法删除,但至少在 Firefox 上可以更改。我解决此问题的方法是将属性 IsValid=true 添加到通过检查的文件中,将 IsValid=false 添加到未通过检查的文件中。

然后我只是循环遍历列表以确保只有带有 IsValid=true 的属性被添加到 FormData

【讨论】:

  • formdata,所以你通过ajax发送?
【解决方案8】:

这是临时的,但我遇到了同样的问题,我用这种方法解决了。在我的情况下,我通过 XMLHttp 请求上传文件,因此我能够通过 formdata 附加发布 FileList 克隆数据。 功能是您可以根据需要多次拖放或选择多个文件(再次选择文件不会重置克隆的文件列表),从(克隆的)文件列表中删除您想要的任何文件,并提交通过xmlhttprequest 什么都留在那里。 这就是我所做的。这是我在这里的第一篇文章,所以代码有点乱。对不起。啊,我不得不使用 jQuery 而不是 Joomla 脚本中的 $。

// some global variables
var clon = {};  // will be my FileList clone
var removedkeys = 0; // removed keys counter for later processing the request
var NextId = 0; // counter to add entries to the clone and not replace existing ones

jQuery(document).ready(function(){
    jQuery("#form input").change(function () {

    // making the clone
    var curFiles = this.files;
    // temporary object clone before copying info to the clone
    var temparr = jQuery.extend(true, {}, curFiles);
    // delete unnecessary FileList keys that were cloned
    delete temparr["length"];
    delete temparr["item"];

    if (Object.keys(clon).length === 0){
       jQuery.extend(true, clon, temparr);
    }else{
       var keysArr = Object.keys(clon);
       NextId = Math.max.apply(null, keysArr)+1; // FileList keys are numbers
       if (NextId < curFiles.length){ // a bug I found and had to solve for not replacing my temparr keys...
          NextId = curFiles.length;
       }
       for (var key in temparr) { // I have to rename new entries for not overwriting existing keys in clon
          if (temparr.hasOwnProperty(key)) {
             temparr[NextId] = temparr[key];
             delete temparr[key];
                // meter aca los cambios de id en los html tags con el nuevo NextId
                NextId++;
          }
       } 
       jQuery.extend(true, clon, temparr); // copy new entries to clon
    }

// modifying the html file list display

if (NextId === 0){
    jQuery("#filelist").html("");
    for(var i=0; i<curFiles.length; i++) {
        var f = curFiles[i];
        jQuery("#filelist").append("<p id=\"file"+i+"\" style=\'margin-bottom: 3px!important;\'>" + f.name + "<a style=\"float:right;cursor:pointer;\" onclick=\"BorrarFile("+i+")\">x</a></p>"); // the function BorrarFile will handle file deletion from the clone by file id
    }
}else{
    for(var i=0; i<curFiles.length; i++) {
        var f = curFiles[i];
        jQuery("#filelist").append("<p id=\"file"+(i+NextId-curFiles.length)+"\" style=\'margin-bottom: 3px!important;\'>" + f.name + "<a style=\"float:right;cursor:pointer;\" onclick=\"BorrarFile("+(i+NextId-curFiles.length)+")\">x</a></p>"); // yeap, i+NextId-curFiles.length actually gets it right
    }        
}
// update the total files count wherever you want
jQuery("#form p").text(Object.keys(clon).length + " file(s) selected");
    });
});

function BorrarFile(id){ // handling file deletion from clone
    jQuery("#file"+id).remove(); // remove the html filelist element
    delete clon[id]; // delete the entry
    removedkeys++; // add to removed keys counter
    if (Object.keys(clon).length === 0){
        jQuery("#form p").text(Object.keys(clon).length + " file(s) selected");
        jQuery("#fileToUpload").val(""); // I had to reset the form file input for my form check function before submission. Else it would send even though my clone was empty
    }else{
        jQuery("#form p").text(Object.keys(clon).length + " file(s) selected");
    }
}
// now my form check function

function check(){
    if( document.getElementById("fileToUpload").files.length == 0 ){
        alert("No file selected");
        return false;
    }else{
        var _validFileExtensions = [".pdf", ".PDF"]; // I wanted pdf files
        // retrieve input files
        var arrInputs = clon;

       // validating files
       for (var i = 0; i < Object.keys(arrInputs).length+removedkeys; i++) {
         if (typeof arrInputs[i]!="undefined"){
           var oInput = arrInputs[i];
           if (oInput.type == "application/pdf") {
               var sFileName = oInput.name;
               if (sFileName.length > 0) {
                   var blnValid = false;
                   for (var j = 0; j < _validFileExtensions.length; j++) {
                     var sCurExtension = _validFileExtensions[j];
                     if (sFileName.substr(sFileName.length - sCurExtension.length, sCurExtension.length).toLowerCase() == sCurExtension.toLowerCase()) {
                       blnValid = true;
                       break;
                     }
                   }
                  if (!blnValid) {
                    alert("Sorry, " + sFileName + " is invalid, allowed extensions are: " + _validFileExtensions.join(", "));
                    return false;
                  }
              }
           }else{
           alert("Sorry, " + arrInputs[0].name + " is invalid, allowed extensions are: " + _validFileExtensions.join(" or "));
           return false;
           }
         }
       }

    // proceed with the data appending and submission
    // here some hidden input values i had previously set. Now retrieving them for submission. My form wasn't actually even a form...
    var fecha = jQuery("#fecha").val();
    var vendor = jQuery("#vendor").val();
    var sku = jQuery("#sku").val();
    // create the formdata object
    var formData = new FormData();
    formData.append("fecha", fecha);
    formData.append("vendor", encodeURI(vendor));
    formData.append("sku", sku);
    // now appending the clone file data (finally!)
    var fila = clon; // i just did this because I had already written the following using the "fila" object, so I copy my clone again
    // the interesting part. As entries in my clone object aren't consecutive numbers I cannot iterate normally, so I came up with the following idea
    for (i = 0; i < Object.keys(fila).length+removedkeys; i++) { 
        if(typeof fila[i]!="undefined"){
            formData.append("fileToUpload[]", fila[i]); // VERY IMPORTANT the formdata key for the files HAS to be an array. It will be later retrieved as $_FILES['fileToUpload']['temp_name'][i]
        }
    }
    jQuery("#submitbtn").fadeOut("slow"); // remove the upload btn so it can't be used again
    jQuery("#drag").html(""); // clearing the output message element
    // start the request
    var xhttp = new XMLHttpRequest();
    xhttp.addEventListener("progress", function(e) {
            var done = e.position || e.loaded, total = e.totalSize || e.total;
        }, false);
        if ( xhttp.upload ) {
            xhttp.upload.onprogress = function(e) {
                var done = e.position || e.loaded, total = e.totalSize || e.total;
                var percent = done / total;
                jQuery("#drag").html(Math.round(percent * 100) + "%");
            };
        }
      xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
         var respuesta = this.responseText;
         jQuery("#drag").html(respuesta);
        }
      };
      xhttp.open("POST", "your_upload_handler.php", true);  
      xhttp.send(formData);
    return true;
    }
};

现在是 html 和样式。我是个新手,但这一切对我来说确实有效,我花了一段时间才弄明白。

<div id="form" class="formpos">
<!--    Select the pdf to upload:-->
  <input type="file" name="fileToUpload[]" id="fileToUpload" accept="application/pdf" multiple>
  <div><p id="drag">Drop your files here or click to select them</p>
  </div>
  <button id="submitbtn" onclick="return check()" >Upload</button>
// these inputs are passed with different names on the formdata. Be aware of that
// I was echoing this, so that's why I use the single quote for php variables
  <input type="hidden" id="fecha" name="fecha_copy" value="'.$fecha.'" />
  <input type="hidden" id="vendor" name="vendorname" value="'.$vendor.'" />
  <input type="hidden" id="sku" name="sku" value="'.$sku.'"" />
</div>
<h1 style="width: 500px!important;margin:20px auto 0px!important;font-size:24px!important;">File list:</h1>
<div id="filelist" style="width: 500px!important;margin:10px auto 0px!important;">Nothing selected yet</div>

样式。我必须标记其中一些!重要以覆盖 Joomla 行为。

.formpos{
  width: 500px;
  height: 200px;
  border: 4px dashed #999;
  margin: 30px auto 100px;
 }
.formpos  p{
  text-align: center!important;
  padding: 80px 30px 0px;
  color: #000;
}
.formpos  div{
  width: 100%!important;
  height: 100%!important;
  text-align: center!important;
  margin-bottom: 30px!important;
}
.formpos input{
  position: absolute!important;
  margin: 0!important;
  padding: 0!important;
  width: 500px!important;
  height: 200px!important;
  outline: none!important;
  opacity: 0!important;
}
.formpos button{
  margin: 0;
  color: #fff;
  background: #16a085;
  border: none;
  width: 508px;
  height: 35px;
  margin-left: -4px;
  border-radius: 4px;
  transition: all .2s ease;
  outline: none;
}
.formpos button:hover{
  background: #149174;
  color: #0C5645;
}
.formpos button:active{
  border:0;
}

我希望这会有所帮助。

【讨论】:

    【解决方案9】:

    感谢@Nicholas Anderson 简单明了,这是您使用 jquery 应用并在我的代码中工作的代码。

    HTML .

    <input class="rangelog btn border-aero" id="file_fr" name="file_fr[]" multiple type="file" placeholder="{$labels_helpfiles_placeholder_file}">
    <span style="cursor: pointer; cursor: hand;" onclick="cleanInputs($('#file_fr'))"><i class="fa fa-trash"></i> Empty chosen files</span>
    

    JS 代码

       function cleanInputs(fileEle){
        $(fileEle).val("");
        var parEle = $(fileEle).parent();
        var newEle = $(fileEle).clone()
        $(fileEle).remove();
        $(parEle).prepend(newEle);
    }
    

    【讨论】:

      【解决方案10】:

      可能有更优雅的方式来做到这一点,但这是我的解决方案。使用 Jquery

      fileEle.value = "";
      var parEle = $(fileEle).parent();
      var newEle = $(fileEle).clone()
      $(fileEle).remove();
      parEle.append(newEle);
      

      基本上,您可以确定输入的值。克隆它并将克隆替换旧的。

      【讨论】:

        【解决方案11】:

        如果您有幸通过文件向数据库发送发布请求,并且您的 DOM 中有要发送的文件

        您可以简单地检查文件列表中的文件是否存在于您的 DOM 中,当然如果不是,您就不要将该元素发送到 de DB。

        【讨论】:

          【解决方案12】:

          我意识到这是一个很老的问题,但是我正在使用 html 多文件选择上传来排队任意数量的文件,这些文件可以在提交之前在自定义 UI 中选择性地删除。

          将文件保存在这样的变量中:

          let uploadedFiles = [];
          
          //inside DOM file select "onChange" event
          let selected = e.target.files[0] ? e.target.files : [];
          uploadedFiles = [...uploadedFiles , ...selected ];
          createElements();
          

          使用“删除文件”创建用户界面:

          function createElements(){
            uploadedFiles.forEach((f,i) => {
          
              //remove DOM elements and re-create them here
              /* //you can show an image like this:
              *  let reader = new FileReader();
              *  reader.onload = function (e) {
              *    let url = e.target.result;
              *    // create <img src=url />
              *  };
              *  reader.readAsDataURL(f);
              */
          
              element.addEventListener("click", function () {
                uploadedFiles.splice(i, 1);
                createElements();
              });
          
            }
          }
          

          提交到服务器:

          let fd = new FormData();
          uploadedFiles.forEach((f, i) => {
            fd.append("files[]", f);
          });
          fetch("yourEndpoint", { 
            method: "POST", 
            body: fd, 
            headers: { 
              //do not set Content-Type 
            } 
          }).then(...)
          

          【讨论】:

            【解决方案13】:

            我混合了许多开发人员的解决方案并达到了这个解决方案。 它会在删除后更改原始数组列表,这意味着如果我们想保存图像,那么我们可以这样做。

            <script>
                var images = [];
                  function image_select() {
                      var image = document.getElementById('image').files;
                      for (i = 0; i < image.length; i++) {
                        images.push({
                            "name" : image[i].name,
                            "url" : URL.createObjectURL(image[i]),
                            "file" : image[i],
                        })
                      }
                      document.getElementById('container').innerHTML = image_show();
                  }
            
                  function image_show() {
                      var image = "";
                      images.forEach((i) => {
                         image += `<div class="image_container d-flex justify-content-center position-relative">
                              <img src="`+ i.url +`" alt="Image">
                              <span class="position-absolute" onclick="delete_image(`+ images.indexOf(i) +`)">&times;</span>
                          </div>`;
                      })
                      return image;
                  }
                  function delete_image(e) {
                    images.splice(e, 1);
                    document.getElementById('container').innerHTML = image_show();
            
                    const dt = new DataTransfer()
                    const input = document.getElementById('image')
                    const { files } = input
            
                    for (let i = 0; i < files.length; i++) {
                        const file = files[i]
                        if (e !== i)
                        dt.items.add(file);
                    }
            
                    input.files = dt.files;
                    console.log(document.getElementById('image').files);
                  }
            </script>
            

            *********这是html代码******

            <body>
                <div class="container mt-3 w-100">
                    <div class="card shadow-sm w-100">
                        <div class="card-header d-flex justify-content-between">
                            <h4>Preview Multiple Images</h4>
                            <form class="form" action="{{route('store')}}" method="post" id="form" enctype="multipart/form-data">
                                @csrf
                                <input type="file" name="image[]" id="image" multiple onchange="image_select()">
                                <button class="btn btn-sm btn-primary" type="submit">Submit</button>
                            </form>
                        </div>
                        <div class="card-body d-flex flex-wrap justify-content-start" id="container">
            
                        </div>
                    </div>
                </div>
            </body>
            

            *********这是CSS代码********

            <style>
                    .image_container {
                height: 120px;
                width: 200px;
                border-radius: 6px;
                overflow: hidden;
                margin: 10px;
            }
            .image_container img {
                height: 100%;
                width: auto;
                object-fit: cover;
            }
            .image_container span {
                top: -6px;
                right: 8px;
                color: red;
                font-size: 28px;
                font-weight: normal;
                cursor: pointer;
            }
                </style>
            

            【讨论】:

              【解决方案14】:

              您可能希望创建一个数组并使用它来代替只读文件列表。

              var myReadWriteList = new Array();
              // user selects files later...
              // then as soon as convenient... 
              myReadWriteList = FileListReadOnly;
              

              在那之后,根据您的列表而不是内置列表进行上传。我不确定您正在使用的上下文,但我正在使用我找到的一个 jquery 插件,我必须做的是获取插件的源代码并使用 &lt;script&gt; 标签将其放入页面中。然后在源代码上方添加了我的数组,以便它可以充当全局变量并且插件可以引用它。

              然后就是换掉引用了。

              我认为这将允许您再次添加拖放操作,如果内置列表是只读的,那么您还能如何将拖放的文件放入列表中?

              :))

              【讨论】:

              • 我写得太早了....似乎当一个 var 设置为等于文件列表时,只读问题又回来了....因此我选择做的是两倍和稍微痛苦但有效...我保留了要上传的文件的可见列表,用户可以从这里删除...显然删除
                  标记中的
                • 标记很简单...所以我来的唯一方法最多是保留已删除文件的辅助列表并在上传过程中引用它......因此,如果文件在上传列表中,我只是跳过它,而用户并不聪明。
              • 当您将FileList 对象分配给myReadWriteList 变量时,它的类型从Array 更改为FileList,因此这不是解决方案。
              【解决方案15】:

              我是这样解决的

               //position  -> the position of the file you need to delete
              
                this.fileImgs.forEach((item, index, object) => {
                   if(item.idColor === idC){
                      if(item.imgs.length === 1){
                          object.splice(index,1) }
                      else{
                         const itemFileImgs = [...item.imgs];
                         itemFileImgs.splice(position,1)
                         item.imgs = [...itemFileImgs] 
                          }
                      }});
                    console.log(this.fileImgs)
              

              【讨论】:

                【解决方案16】:

                在 vue js 中:

                self.$refs.inputFile.value = ''

                【讨论】:

                • 这种方法会删除所有文件。不是一个文件。
                【解决方案17】:

                我只是将输入类型更改为文本并返回文件:D

                【讨论】:

                • 这被视为评论
                • 应该如何工作?你是怎么做到的?
                猜你喜欢
                • 2017-12-29
                • 2016-09-29
                • 2013-06-01
                • 1970-01-01
                • 2020-12-22
                • 2013-02-14
                • 1970-01-01
                • 1970-01-01
                相关资源
                最近更新 更多