HTML代码
<input ref="imgFile" type="file" accept="image/jpeg,image/png" hidden name="file" multiple="multiple" @change="getMyFile">
JS代码
getMyFile(e){ const self=this let files=e.target.files if(files && files[0]){ for(let i=0;i<files.length;i++){ this.fileImgList.push(files[i]) let url = this.getFileUrl(files[i]); self.showUpImgList.push(url) } console.log(files) } }, //获取文件本地地址 getFileUrl(file) { var url; var agent = navigator.userAgent; if (agent.indexOf("MSIE") >= 1 || agent.indexOf("NET")!=-1) { url = window.URL.createObjectURL(file); } else if (agent.indexOf("Firefox") > 0) { url = window.URL.createObjectURL(file); } else if (agent.indexOf("Chrome") > 0) { url =window.webkitURL.createObjectURL(file); } return url; },
原文:https://www.cnblogs.com/bingying312/p/14840759.html