Vue application elementUI upload component upload (picture, pdf) preview problem?

problem description

clipboard.png

use the upload upload component of elementUI to upload (picture, pdf) click how to achieve the preview function?

tried the method

try to use the browser function to do local preview ie has a compatibility problem with blob, how do you deal with it?

related codes

 handlePreview(file) {
    const userAgent = navigator.userAgent;
    if (!!window.ActiveXObject || "ActiveXObject" in window) {
        alert("")
    }else{
      window.open(file.url) //blob
    }
  }
Jun.15,2021

does not understand what you mean


if(file.includes('.pdf')){
    let url = file.url;
    const elink = document.createElement('a');
    elink.href = basePdfUrl + encodeURIComponent(url); //basePdfUrl pdf.js
    elink.target= '_block';
    document.body.appendChild(elink);
    elink.click();
    document.body.removeChild(elink);
}else{
    ...
}

this is how I solved it. It is compatible with ie and pdf.js plug-in to realize the preview of pdf

.
Menu