最近遇到要下載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()
})
},