当前位置: 首页 > news >正文

vue实现文件在线预览功能(包含docx,excel,pdf)

npm install--save @vue-office/docx @vue-office/excel @vue-office/pdf vue-demi

或者

yarn add @vue-office/docx @vue-office/excel @vue-office/pdf vue-demi
<template><a-card:bordered="false"><!--查询区域--><a-button type="link"size="small"@click="handlePreview2(record)">预览</a-button><a-modal destroyOnClose:visible="comShow":title="modalTitle":width="dynModelWidth":okButtonProps="{ class:{'jee-hidden': true} }"@cancel="handleCancel"><Watermark:text="watermarkText":opacity="0.3":fontSize="20":rotate="0"/><component:is="renderCom":src="url2"@rendered="rendered"@error="errorHandler"class="size-100"/></a-modal></a-card></template><script>// 引入VueOfficeDocx组件importVueOfficeDocxfrom"@vue-office/docx";// 引入相关样式import"@vue-office/docx/lib/index.css";// 引入VueOfficeExcel组件importVueOfficeExcelfrom"@vue-office/excel";// 引入相关样式import"@vue-office/excel/lib/index.css";// 引入VueOfficePdf组件importVueOfficePdffrom"@vue-office/pdf";exportdefault{name:'MesQualityFileListSearch',mixins:[JeecgListMixin,mixinDevice],components:{VueOfficeDocx,VueOfficeExcel,VueOfficePdf,},data(){return{dynModelWidth:'60%',modalTitle:'',comShow:false,renderCom:"VueOfficeDocx",url2:'',}},methods:{handlePreview2(record){this.getDetail(record.id)},handleCancel(){this.comShow=false;},rendered(){console.log("渲染完成");},errorHandler(){console.log("预览渲染失败,请重试");},/** * 根据文件扩展名渲染指定预览组件 * */getDetail(id){if(id){letparam={id:id,}getAction(this.url.queryDetail,param).then((res)=>{if(res.success){letfileArr=res.result.filesthis.comShow=true;this.dynModelWidth='80%',this.modalTitle=fileArr[0].fileNamethis.url2=fileArr[0].fileUrl console.log(this.url2)// 根据文件格式显示预览组件constfileExtension=fileArr[0].fileName.split(".").pop().toLowerCase();if(fileExtension==="xlsx"){this.renderCom="VueOfficeExcel";}if(fileExtension==="docx"){this.renderCom="VueOfficeDocx";}if(fileExtension==="pdf"){this.renderCom="VueOfficePdf";}}})}},}}</script><style scoped>@import'~@assets/less/common.less';.size-100{width:100%;height:100%;min-height:500px;}</style>
http://www.cnnetsun.cn/news/86790.html

相关文章:

  • FaceFusion报错:未检测到源人脸
  • Tigshop 开源商城系统 【商品预售功能】上新!全款+定金双模式深度适配全行业经营需求
  • YOLOv8官方文档中文解读:新手必读
  • 基于深度学习的植物病害检测系统(UI界面+YOLOv8/v7/v6/v5代码+训练数据集)
  • Stable Diffusion 3.5本地部署指南与一键整合包
  • Wan2.2-T2V-A14B本地部署与多GPU推理指南
  • 基于深度学习的跌倒检测系统(UI界面+YOLOv8/v7/v6/v5代码+训练数据集)
  • 构建个性化AI助手:LobeChat + 开源大模型完美组合
  • 免费守护网站安全:精选一年期SSL证书获取攻略
  • 私有化部署AI知识库——Anything-LLM企业级解决方案详解
  • 如何利用PaddlePaddle和清华源快速搭建高性能NLP训练环境
  • NVIDIA TensorRT镜像安装包下载与CUDA安装全攻略
  • kotaemon配置全解析:轻松定制文档问答系统
  • ACE-Step:开源生成式AI音乐模型解析
  • Seed-Coder-8B-Base能否辅助编写Istio AuthorizationPolicy?
  • Langflow本地部署:解决pip安装卡顿问题
  • LobeChat如何应对高并发请求?压力测试结果公布
  • LobeChat能否组织线上讲座?知识传播新形式
  • Qwen3-VL-8B如何实现近实时视频分析?
  • ACE-Step:开源生成式AI音乐大模型详解
  • LobeChat能否写作小说?创意灵感激发神器
  • Java大厂面试实录:面试官与谢飞机的爆笑对战
  • Bootstrap:随机森林的“多样性引擎”与量化利器
  • 块状Bootstrap:让金融时间序列“记忆”不丢失的魔法
  • 利用清华源加速TensorRT相关依赖的npm安装过程
  • 跨界转型AI产品经理:非算法专业出身的成功之道,揭秘大模型时代的新机遇!
  • 小学物理竞赛考试题目要点
  • Qwen3-VL-30B GPU配置与显存优化全指南
  • Excalidraw Webhook事件机制实现外部系统联动
  • 乔家大院漫游记:在晋商老宅里读懂百年风华