vue:input file 多選時獲取File方法


<input type="file" name="file" @change="selectPhoto($event)" accept="image/*"multiple>
selectPhoto(event){
                console.log(event.target.files)
                let fileList = event.target.files
                for(let i=0;i<fileList.length;i++){
                    this.fileArry.push(fileList[i])
                    let fileUrl = URL.createObjectURL(fileList[i]);  // 獲取文件url
                    this.list.push({msrc:fileUrl,src:fileUrl}) // data中顯示的圖片url 
                }
                // let fileList=$(".photoFile").get(0).files[0] // 獲取input file 文件信息
                // let fileUrl = URL.createObjectURL(fileList);  // 獲取文件url
                // this.fileArry.push(fileList)
                console.log(this.fileArry)
                // this.list.push({msrc:fileUrl,src:fileUrl}) 
                event.target.value = "" // 解決不能選同一個文件
          },

 解決:文件不能多選,不能同時上傳同一個文件和能獲取多選文件的長度


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM