后端返回 下载地址url 前端下载

65 阅读1分钟
 xxxxxx(data).then((res) => {
        console.log(res);
        if (res.Data) {
          // console.log('res.Data: ', res.Data)
          const link = document.createElement("a");
          //_blank表示在新窗口打开链接
          link.target = "_blank";
          link.href = "xxxxxxxx" + res.Data;
          link.setAttribute("download", this.reportName + ".pdf"); // 下载文件的名称及文件类型后缀
          document.body.appendChild(link);
          link.click();
          document.body.removeChild(link); // 下载完成移除元素
          DelFile({
            FileName: res.Data,
          }).then((Result) => {
            console.log(Result);
          });
        } else {
          this.$message({
            type: "info",
            message: "暂无此文件",
          });
        }
      });