前端实现文件在线预览txt,pdf,doc,xls,ppt几种格式
做法就是使用iframe标签 1.text,pdf的文件预览 <iframe class="filename" :src="文件的地址" width='100%' height='600' frameborder='1' ></iframe> 2.doc,xls,ppt等office的预览 <iframe class="filename" :src="https://view.officeapps.live.com/op/view.aspx?src=后面是文件的地址" width='100%' height='600' frameborder='1' ></iframe> 3.我们可以看出,差别只有src的属性,所以要设置文件预览同时可以满足txt,pdf,和office类型格式的文件,只需要配置src就可以,根据文件后缀判断如果是office的类型就在url前加上 https://view.officeapps.live.com/op/view.aspx?src= for (let i=0;i<this.data.quoteInfo.goodsList.length;i++) { for(let j=0;j<this.data.quoteInfo.goodsList[i].goodsAttachments.fileAttachmentList.length;j++){ let