使用的是element UI弹框 el-dialog,别的也能照常使用
excel
word
pdf
Word,Excel 预览
<el-dialog
:visible.sync="fileshow"
:close-on-click-modal="false"
class="pdfshow-dialog"
title="预览"
width="90%">
<iframe :src='fileSrc' width="100%" height="100%"
frameborder="0" scrolling="auto"
style="position:absolute;left: 0px;z-index:1000">
</iframe>
<span slot="footer" class="dialog-footer">
<el-button type="primary">关闭</el-button>
<el-button type="primary">下载</el-button>
</span>
</el-dialog>
给fileSrc赋值
getfileSrc(file) {
if (/\.(xlsx|xls|doc|docx)$/.test(file.url)){ //Word,Excel 文件
this.fileSrc='https://view.officeapps.live.com/op/view.aspx?src='+file.url
this.pdfshow = true
}else if(/\.(pdf|PDF)$/.test(file.url)){ //pdf文件
this.fileshow= true
this.fileSrc = file.url
}else{
this.$message.warning('该格式暂不支持预览');
}
},
目前只支持地址文件,本地文件好像不行