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