• 前端如何下载文件


    xls,xlsx 格式
     
    if (res.status == 200) {
    const content = res.data;
    const blob = new Blob([content]);
    const fileName = "XXXXX.xls";
    if ("download" in document.createElement("a")) {
    // 非IE下载
    const elink = document.createElement("a");
    elink.download = fileName;
    elink.style.display = "none";
    elink.href = URL.createObjectURL(blob);
    document.body.appendChild(elink);
    elink.click();
    URL.revokeObjectURL(elink.href); // 释放URL 对象
    document.body.removeChild(elink);
    } else {
    // IE10+下载
    navigator.msSaveBlob(blob, fileName);
    }
     
    pdf 格式
    this.$http({
    method: "post",
    responseType: "arraybuffer",
    url: "http://172.16.2.77:9001/api/RepairProcess/GetHistoryForDPF",
    data:qs.stringify(params)
    }).then(res => {
    if (res.status == 200) {
    let blob = new Blob([res.data], {
    type: `application/pdf` //word文档为msword,pdf文档为pdf
    });
    let objectUrl = URL.createObjectURL(blob);
    let link = document.createElement("a");
    let fname = this.RepairId; //下载文件的名字
    link.href = objectUrl;
    link.setAttribute("download", fname);
    document.body.appendChild(link);
    link.click();
    } else {
    this.$message({
    type: "error",
    message: "导出失败"
    });
    }
    });
  • 相关阅读:
    模块二
    lambda map() filter() zip()练习
    装饰器
    函数模块回顾
    连接不同数据OleDb(不完整)
    连接不同的数据库
    连接数据库ORACLE(不完整)
    多数据之间的连接操作ODBC(不完整)
    ora0131
    ORACLE linux 下 sqlplus命令
  • 原文地址:https://www.cnblogs.com/wgy0528/p/10031176.html
Copyright © 2020-2023  润新知