js 下载多个文件 vue

147 阅读1分钟
// fileUrl: Array(2)

//0: "http://10.41.72.118:8001/browser/411.txt" // "http://10.41.72.118:8001/browser/412.txt"

async exportLog() {
      try {
        let result =await resources.browserconsole.Terminal.ExportLog({
          macAddress: this.itemMacAddress
        });
        const fileUrl = get(result, 'data.fileUrl', null);
        if (fileUrl != null) {
          // window.open(fileUrl, ''); //只适用于下载1个文件
          fileUrl.forEach(v => {
            this.downloadFile(v);//循环调用方法
          });
        }
      } catch (err) {
        this.$alert(err, '提示')
      }
    },
    downloadFile(url){//下载文件方法
      const iframe = document.createElement("iframe");
      iframe.style.display = "none";  // 防止影响页面
      iframe.style.height = 0;  // 防止影响页面
      iframe.src = url;
      document.body.appendChild(iframe);// 这一行必须,iframe挂在到dom树上才会发请求
      setTimeout(()=>{
        iframe.remove();
      }, 5 * 60 * 1000);
    },