多个文件下载

        this.file_url = ["http://123", "http://1234", "http://1235"];//文件地址
        // a链接版本--下载文件
        for (let i = 0; i < this.file_url.length; i++) {
          let url = window.URL.createObjectURL(new Blob([this.file_url[i]]));
          let link = document.createElement("a");
          link.style.display = "none";
          link.href = url;
          let fileName = this.file_url[i].substring(
            this.file_url[i].lastIndexOf("/") + 1,
            this.file_url[i].length
          );
          link.setAttribute("download", fileName);
          document.body.appendChild(link);
          link.click();
        }

        // iframe版本--下载文件
        for (let i = 0; i < this.file_url.length; i++) {
          const iframe = document.createElement("iframe");
          iframe.style.display = "none"; // 防止影响页面
          iframe.style.height = 0; // 防止影响页面
          iframe.src = this.file_url[i]; // url自己进行指定
          document.body.appendChild(iframe); // 这一行必须,iframe挂在到dom树上才会发请求
          setTimeout(() => {
            iframe.remove(); // 5分钟之后删除
          }, 5 * 60 * 1000);
       }
posted @ 2021-09-10 10:44  歇歇吧  阅读(19)  评论(0编辑  收藏  举报