当前位置:网站首页>在线预览PDF文件功能实现
在线预览PDF文件功能实现
2022-04-22 04:48:00 【子墨将】
在线预览PDF文件功能实现
前端
HTML
<a @click="previewPdf(record.REPORT_NAME,record.REPORT_PATH)">预览</a>
JS
请求方法的封装,request 是 axios.create()的实例对象,根据文件地址路径,请求到文件数据,并且返回接收类型是Blob对象
export function downloadFile (params) {
return request({
url: api.downloadFile,
method: 'post',
data: params,
responseType: 'blob' //重点部分:返回格式必须是 blob
})
}
URL.createObjectURL() 静态方法会创建一个 DOMString,其中包含一个表示参数中给出的对象的URL。这个 URL 的生命周期和创建它的窗口中的 document 绑定。这个新的URL 对象表示指定的 File 对象或 Blob 对象。
previewPdf (fileName, filePath) {
downloadFile({
filePath: filePath }).then(res => {
// console.log(res)
var blob = new Blob([res], {
type: 'application/pdf' })
const url = URL.createObjectURL(blob)
window.open(url)
}).catch(req => {
this.$message.error('预览失败,无法找到文件')
console.log('失败原因', req)
})
}
版权声明
本文为[子墨将]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_40864434/article/details/124318282
边栏推荐
- [Chestnut Sugar GIS] SuperMap - How to make hyperlinks for Data
- [stack and queue] simple application of C language ⌊ stack and queue realize each other, circular queue ⌉
- 2022g2 power station boiler stoker examination exercises and online simulation examination
- 不同品牌设备如何兼容实现互联?一文教你看懂
- I'll test the timing again
- Sharing of enterprise data leakage prevention scheme
- 使用指定显卡
- Linear regression of machine learning
- 11.libevent对水平触发和边缘触发测试
- 14. Buffferevent timeout event processing
猜你喜欢

企业数据防泄露方案分享

Thread pool status + ThreadPoolExecutor
Apple plans to expand children's information and communication security features to the UK and Canada

2022 P cylinder filling training questions and answers

Carina local storage selected into the CNCF cloud native panorama

2022t elevator repair test exercises and online simulation test

线程池状态+ThreadPoolExecutor

Application of an open current transformer with switching value

SCI paper writing -- word template of IEEE Journal (also available in latex)

CommDGI: Community detection oriented deep graph infomax 2020 CIKM
随机推荐
labelme的常用命令
Paper reading (48): a library of optimization algorithms for organizational design
12.libevent循环函数和退出测试
Setting method of parameters such as color and linetype of MATLAB curve
Deployment of web server, personal experience
【Selenium】UnitTest测试框架的基本应用
14.buffferevent超时事件处理
Win10 Caton repair
LeetCode 剑指 Offer 15. 二进制中1的个数
Linked list Part III
Small bug -- hidden problem of Guide Package
Inotify Brief
15. Bufferevent client test connection server
Kaggle actual combat 4.1 -- time series prediction problem
[chestnut sugar GIS] ArcMap - Model Builder - batch clipping grid data
[chestnut sugar GIS] ArcMap - how to make map combination table with buffer
Boyun beyondcmp cloud management platform version 5.6 release
Leetcode refers to offer 68 - I. the nearest common ancestor of the binary search tree
C-随手写10
JVM throughput