場景: 請求到的PDF(url鏈接),將其展示在頁面上
插件: pdfobject? ?(我使用的版本:?"pdfobject": "^2.2.12"?)
下載插件就不多說了,下面將其引入:
<div id="pdf"></div>
import PDFobject from "pdfobject";
?這里的this.url? 就是請求回來的pdf url地址
new Promise((resolve, reject) => {const xhr = new XMLHttpRequest();xhr.open("GET", this.url, true);xhr.responseType = "blob";xhr.onload = function () {if (this.status == 200) {resolve(this.response);} else {reject(this.statusText);}};xhr.onerror = function () {reject(this.statusText);};xhr.send();}).then((blob) => {PDFobject.embed(URL.createObjectURL(blob), "#pdf");});
這里的請求回來的url地址要先轉為二進制.??
親測有效!
這是在界面顯示的樣子