0
点赞
收藏
分享

微信扫一扫

前端Vue下载文件

兔八哥软件爱分享 2022-03-30 阅读 183
          1. 第一种
          exportProjectListExcel(params).then((response) => { // 传参调接口获取blob文件
            if (response) { // respone为blob类型
              let exportFileName = "项目检索列表.xlsx";
              this.download(response, exportFileName);
            }
          });
          download(data, filename) {
            if (data == null) {
            } else {
              let url = window.URL.createObjectURL(new Blob([data]));
              let link = document.createElement("a");
              link.style.display = "none";
              link.href = url;
              link.setAttribute("download", filename);
              document.body.appendChild(link);
              link.click();
            }
          }
          2. 第二种 此时文件放置在public文件夹下
          <el-link href="./templateFiles/项目批量导入模板.xls">
            <el-button type="info" icon="el-icon-download">导入模版下载</el-button>
          </el-link>
          3. url下载
          downloadFile(fileId) {
              downloadFile(fileId).then((res) => {
                console.log("url", res.data);
                window.open(res.data.url, "_self");
              });
          },
举报

相关推荐

0 条评论