使用axios下载文件流

axios({
      method: "post",
      url: "你的url"
      // 这里可以在header中加一些东西,比如token
    })
      .then(res => {
        console.log("response: ", res);
        // new Blob([data])用来创建URL的file对象或者blob对象
        let url = window.URL.createObjectURL(new Blob([res.data])); 
        // 生成一个a标签
        let link = document.createElement("a");
        link.style.display = "none";
        link.href = url;
        // 生成时间戳
        let timestamp=new Date().getTime();   
        link.download = timestamp + ".pdf";   
        document.body.appendChild(link);
        link.click();
      })
      .catch(error => {
        console.log("response: ", error);
      });

你可能感兴趣的:(使用axios下载文件流)