VUE通过get方法下载文件(文件下载需要传参数) 直接通过链接下载文件

383 阅读1分钟

VUE通过get方法下载文件(文件下载需要传参数) 直接通过链接下载文件

VUE通过get方法下载文件(文件下载需要传参数) 直接通过链接下载文件_vue get下载文件_不想学习只想玩的博客-CSDN博客

VUE通过get方法下载文件(文件下载需要传参数)

this.$axios.get(自己下载文件的url, {
          headers: {
          //携带token
            token: window.localStorage.getItem('authToken')
          },
          
          responseType: "arraybuffer",
          //携带的参数
          params: {
            ids: params.dataAnnexPath,
            subjectType: params.subjectType
          }

        }).then(res => {
          let blob = new Blob([res.data], {
            type: "application/vnd.ms-excel"  //文件类型
          });
          let eLink = document.createElement("a");
          eLink.download = "解析数据.xlsx";
          eLink.style.display = "none";
          eLink.href = URL.createObjectURL(blob);
          document.body.appendChild(eLink);
          eLink.click();

          document.body.removeChild(eLink);
          URL.revokeObjectURL(eLink.href);

        }).catch(req => { })

直接通过链接下载文件

 window.open(自己下载文件的url + '?deliveryId=' + params.deliveryId)