office文件 vue 预览_vue实现预览功能(包括doc,pdf,图片,视频)

本文介绍了一个Vue组件,用于预览包括doc、docx、xlsx、pdf、图片和视频在内的多种文件类型。通过检查文件后缀,使用不同的预览方式:PDF使用特定URL,图片使用图片查看器,视频则加载到播放器中。不支持的文件类型会提示无法预览。
摘要由CSDN通过智能技术生成

* pdf预览

*/

previewPdf(row) {

let type = this.iconByType(row);

this.fileUrl = row.url

if (type.indexOf("doc") != -1 || type.indexOf("docx") != -1 || type.indexOf("xsl") != -1 || type.indexOf("xslx") != -1) {

this.showDoc = true

} else if (type.indexOf("pdf") != -1) {

this.pdfUrl = "http://47.105.218.26:8888/group1/M00/00/00/rB-LJlzT042AbKdCAAiu_35Yccs182.pdf"

this.showPdf = true

} else if (type.indexOf("jpg") != -1 || type.indexOf("png") != -1 || type.indexOf("jpeg") != -1) {

this.images = this.getUrlListByName(row.url)

const viewer = this.$el.querySelector('.images').$viewer

viewer.show()

} else if (type.indexOf("avi") != -1 || type.indexOf("mp4") != -1 || type.indexOf("webm") != -1 || type.indexOf("m4v") != -1 || type.indexOf("rmvb") != -1 || type.indexOf("mpg") != -1 || type.indexOf("3gp") != -1 || type.indexOf("swf") != -1 || type.indexOf("mkv") != -1) {

this.positivePlayerOptions.sources[0].src = "//nos.netease.com/vod163/demo.mp4"

this.positivePlayerOptions.sources[0].type = "video/mp4"

this.showVideo = true

} else {

this.$message("当前文件暂不支持预览")

}

// this.showPdf = true

},

/**

* 通过文件后缀返回文件的图标

*/

iconByType(row) {

return row.fileName.substring(row.fileName.lastIndexOf(".") + 1, row.fileName.length)

},

closePreviewClick() {

if (this.showDoc == true) {

this.showDoc = false

} else if (this.showPdf == true) {

this.showPdf = false

} else if (this.showVideo == true) {

this.showVideo = false

}

},

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值