赞
踩
<van-image-preview v-model="showPicture" :images="images" :startPosition="startPositionIndex"/>
获取图片路劲方法
//获取图片路径 async getFile(res) { for(let i = 0; i < res.length; i++) { //请求接口 await this.$http.get('/aeo_smart/ICommonApi.do?viewFile_chapter', { params: { fileid: res[i].id, subclassname: res[i].subclassname, fid: res[i].id }, responseType: 'blob' }) .then((response) =>{ let dataInfo = response.data let fileHeader = ''; let typeContent = dataInfo.type; //判断类型是否是图片类型 if(res[i].extend == 'png' || res[i].extend == 'gif' || res[i].extend == 'x-icon' || res[i].extend == 'jpg') { fileHeader = "data:image/png;base64,"; //设置base64 的格式 typeContent = "image/" + res[i].extend; //设置blob的格式 // 生成blob图片,需要参数(字节数组, 文件类型) let blob = new Blob([dataInfo], { type: typeContent }) //创建FileReader对象 const reader = new FileReader(); let url = ''; reader.onload = function (e) { //取到文件预览路径 url = e.target.result } setTimeout(rese => { this.path.push(url); //添加到预览的列表中 this.images.push(url); this.iamgeFileName.push(res[i].id); }, 500) //读取blob对象,获得URL格式的字符串(base64编码)以表示所读取文件的内容 reader.readAsDataURL(blob); } else { setTimeout(rese => { this.path.push(this.realpath); }, 500) } }) .catch(function (error) { console.log(error); }); } },
效果
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。