zoukankan      html  css  js  c++  java
  • 文件流下载excel表格

          let parms = `?start=${this.searchForm.timeValue[0]}&end=${this.searchForm.timeValue[1]}&centerId=${this.searchForm.centerId}&customerId=${this.searchForm.customerId}&queryStr=${this.searchForm.queryStr}&status=${3}`
    
          axios({ // 用axios发送请求
            method: 'get',
            url: baseURL + '/sales/order/realTimeOrderExport' + parms, // 请求地址
            headers: {
              token: store.state.UserToken
            },
            responseType: 'blob' // 表明返回服务器返回的数据类型
          }).then((res) => { // 处理返回的文件流
            const content = res.data // 返回的内容
            const fileName = '明细下载.xlsx'// 下载文件名
            download(content, fileName)
          }).catch(e => {
            this.$message.error('获取自雇者协议出错')
          })
          function download (content, fileName) {
            const blob = new Blob([content]) // 创建一个类文件对象:Blob对象表示一个不可变的、原始数据的类文件对象
            const url = window.URL.createObjectURL(blob)// URL.createObjectURL(object)表示生成一个File对象或Blob对象
            let dom = document.createElement('a')// 设置一个隐藏的a标签,href为输出流,设置download
            dom.style.display = 'none'
            dom.href = url
            dom.setAttribute('download', fileName)// 指示浏览器下载url,而不是导航到它;因此将提示用户将其保存为本地文件
            document.body.appendChild(dom)
            dom.click()
          }
  • 相关阅读:
    idea创建项目报错(Maven execution terminated abnormally (exit code 1) )解决方案
    mysql连接查询
    mysql特殊使用
    eclipse发布web
    eclipse启动web应用 报错
    hdu 2018
    atom安装插件失败 latex
    牛腩新闻发布系统——解惑:VS2012验证码加载不出来
    IIS的安装和配置
    InoReader——网页无法打开
  • 原文地址:https://www.cnblogs.com/yn-cn/p/15239189.html
Copyright © 2011-2022 走看看