vue 下载pdf

1、html

   <div class="down" @click="down(dataurl)">
         <img src="~assets/images/reportsModule/下载.png" alt="">
         <span style="padding-left: 5px;">立即下载</span>
      </div>

   dataurl 是路径

2、methods

  // 下载pdf
     download(url){
          const link = document.createElement("a");
          // 这里是将链接地址url转成blob地址,
          fetch(url)
          .then((res) => res.blob())
          .then((blob) => {
               link.href = URL.createObjectURL(blob);
               // 下载文件的名称及文件类型后缀
               link.download = "文件";
               document.body.appendChild(link);
               link.click();
               //在资源下载完成后 清除 占用的缓存资源
               window.URL.revokeObjectURL(link.href);
               document.body.removeChild(link);
          });
     },
   // 下载pdf
     down(e){
          let obj = {
               type: 3,
               path: e
          }
          接口(参数).then(res => {
             this.download(e)
          }).catch(err =>{
               console.log(err)
          })
     },

相关推荐

  1. vue 下载pdf

    2024-04-30 07:30:01       32 阅读
  2. vue 下载pdf以及其他文件方法

    2024-04-30 07:30:01       50 阅读
  3. vue 实现下载pdf格式的文件

    2024-04-30 07:30:01       43 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-30 07:30:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-30 07:30:01       101 阅读
  3. 在Django里面运行非项目文件

    2024-04-30 07:30:01       82 阅读
  4. Python语言-面向对象

    2024-04-30 07:30:01       91 阅读

热门阅读

  1. ARM Summary 4 I2C communication

    2024-04-30 07:30:01       30 阅读
  2. 安卓第三方app调用system/lib库报错的问题

    2024-04-30 07:30:01       30 阅读
  3. Linux:升级OpenSSL和OpenSSH

    2024-04-30 07:30:01       33 阅读
  4. [STL剖析] 01 引言

    2024-04-30 07:30:01       30 阅读
  5. 亲子公园剧本杀小程序ar互动寻宝游戏开发搭建

    2024-04-30 07:30:01       34 阅读
  6. leetcode1329--将矩阵按对角线排序

    2024-04-30 07:30:01       37 阅读
  7. 第11章:GO的微服务架构

    2024-04-30 07:30:01       31 阅读
  8. 用二分法开平方根求其整数部分

    2024-04-30 07:30:01       32 阅读
  9. ctf-web入门详解思路

    2024-04-30 07:30:01       25 阅读
  10. 兰姆顿食尸鬼

    2024-04-30 07:30:01       27 阅读
  11. 解决 Pytorch 和 Cuda 版本不兼容问题

    2024-04-30 07:30:01       25 阅读
  12. 我的创作纪念日

    2024-04-30 07:30:01       28 阅读