// type1
      await getFile(fileUrl).then((res) => {
      console.log('download',res);
      let bFile = window.URL.createObjectURL(
        new Blob([res])
      )
      this.download(bFile, this.viewData.file_name)
    });

    // type2
    window.open(fileUrl)
    // type3
    setTimeout(() => {
    let a = document.createElement("a");
    let url = fileUrl; //下载url
    let filename = "download";
    a.href = url;
    a.download = filename;
    a.click();
    }, 500);
    // type4
    setTimeout(() => {
      let myFrame = document.createElement("iframe");
      myFrame.src = fileUrl;
      myFrame.style.display = "none";
      document.body.appendChild(myFrame);
      window.open(fileUrl);
    }, 500);
    // type5
      let url = "fileurl" // 文件绝对路径
      var a = document.createElement("a");
      a.setAttribute("href", url);
      a.setAttribute("target", "_blank");
      let clickEvent = document.createEvent("MouseEvents");
      clickEvent.initEvent("click", true, true);
      a.dispatchEvent(clickEvent);
posted on 2021-11-01 13:39  夜攸  阅读(569)  评论(0编辑  收藏  举报