
<el-button :loading="pdfIslock" v-if="isPDFFile(form.pic)" type="primary" style="margin: 15px 0" @click="previewPDF(form.pic)"> 预览pdf
</el-button>//npm install pdfjs-dist //如果没有就得先安装import pdf from 'vue-pdf';
components: {pdf,},data(){return {pdfIslock: false,pdfUrl: "",showDialog: false, }
}previewPDF(url){if(this.pdfIslock){this.$message.warning("文件下载中")return}this.pdfIslock = true if(!url){this.$message.error("请先上传文件")return}const that = thislet params = {fileName: url.split("/").pop()}
//fileProxyPdf 是后端的接口 返回的是一个pdffileProxyPdf(params).then((response) => { const blob = new Blob([response.data], { type: 'application/pdf' });const ourl = window.URL.createObjectURL(blob);// 将Object URL赋值给pdfUrlthis.pdfUrl = ourlthis.showDialog = true this.pdfIslock = false }).catch(function(){that.$message.error("下载失败,请稍后重试")that.pdfIslock = false }); //window.open(url, '_blank');},