URL.createObjectURL(blob) 中的 blob 給出錯誤:“Object”型別的引數不可分配給“Blob |”型別的引數 媒體源”。有什么解決方案來解決這個問題嗎?
async downloadPDF(): Promise<void> {
try{
this.http.post(environment.pdf_url, { responseType: 'blob'}).subscribe(
(blob) => {
const a = document.createElement('a')
const objectUrl = URL.createObjectURL(blob)
a.href = objectUrl
a.download = `xxxxx.pdf`;
a.click();
URL.revokeObjectURL(objectUrl);
}
)
} catch (err) {
console.log(err)
}
}
uj5u.com熱心網友回復:
您正在執行 post 方法并且缺少 body 引數,您將直接使用代碼訪問 options 引數。將其更改為:
this.http.post(environment.pdf_url, {}, { responseType: 'blob'})
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/491265.html
