首页 > 其他 > 详细

获取文件本地地址,预览图片

时间:2021-06-02 15:50:53      阅读:30      评论:0      收藏:0      [点我收藏+]

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!