💡在线预览PDF文件功能实现
📊前端
🍁HTML
<a @click="previewPdf(record.REPORT_NAME,record.REPORT_PATH)">预览</a>
⛄JS
export function downloadFile (params) {
return request({
url: api.downloadFile,
method: 'post',
data: params,
responseType: 'blob'
})
}
previewPdf (fileName, filePath) {
downloadFile({ filePath: filePath }).then(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)
})
}