• 请求二进制流文件,并转码下载


     
    this.$http({
    url: this.exportUrl,
    data: this.useSearch,
    responseType: 'blob'
    })
    .then((res) => {
    const blob = new Blob([res.data], { type: "application/x-xls" })
    // for IE
    if (window.navigator && window.navigator.msSaveOrOpenBlob) {
    window.navigator.msSaveOrOpenBlob(blob, this.downloadName || '表格.xls');
    } else {
    // 兼容不同浏览器的URL对象
    const url = window.URL || window.webkitURL || window.moxURL
    // 创建下载链接
    const downloadHref = url.createObjectURL(blob)
    // 创建a标签并为其添加属性
    let downloadLink = document.createElement('a')
    downloadLink.href = downloadHref
    downloadLink.download = this.downloadName || '表格.xls';
    // 触发点击事件执行下载
    downloadLink.click()
    }
    })
    .finally(() => {
     
    })
  • 相关阅读:
    css 基础
    css 基础-1
    html 入门2-表
    CMDB (后台管理) CURD 插件
    序列化
    AES(高级加密)
    API验证
    数据库取时间(分组)
    用户权限 (知识点)
    xss 过滤
  • 原文地址:https://www.cnblogs.com/gudun/p/10619344.html
Copyright © 2020-2023  润新知