關於PDF文件流的下載

 最近遇到要下載pdf的需求,於是一頓亂敲代碼,成功。代碼如下,axios請求裏的代碼複製粘貼即可使用:

 getAgreementDetailRequest().then(res => {
        console.log(res);
        let url = window.URL.createObjectURL(new Blob([res]))
        console.log(url);
        let link = document.createElement('a')
        link.style.display = 'none'
        link.href = url
        link.setAttribute('download', 'test.pdf')

        document.body.appendChild(link)
        link.click()
         
      })
    },

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章