0
点赞
收藏
分享

微信扫一扫

在线预览PDF文件功能实现

kolibreath 2022-04-21 阅读 70
前端

💡在线预览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' //重点部分:返回格式必须是 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)
      })
    }
举报

相关推荐

0 条评论