zoukankan      html  css  js  c++  java
  • get 加 header 下载文件 函数,虽然最后没用。

    export const apiDown = (url, data = {}) => {
      let data2 = secretFilter(data)
      axiosDown({
        url,
        params: data2,
        method: 'get',
        responseType: 'blob',
        headers: {
          'moudleId': 'rim',
          // 'Content-Type': _contentType,
          token: getToken() ? getToken() : ''
        }
      }).then(response => {
        console.info('apiGet res', response)
        if (response.data.type == 'application/octet-stream') {
          let filename = ''
          if (response.config.params.fileName) {
            filename = decrypt2(response.config.params.fileName)
          }
          if (response.config.params.id) {
            console.info('response.config.params.id', response.config.params.id)
            filename = base64ToStr(response.config.params.id).split('_')[1]
          }
          const blob = new Blob([response.data])
          var downloadElement = document.createElement('a')
          var href = window.URL.createObjectURL(blob)
          downloadElement.href = href
          downloadElement.download = filename
          document.body.appendChild(downloadElement)
          downloadElement.click()
          document.body.removeChild(downloadElement)
          window.URL.revokeObjectURL(href)
        }
      })
    }
    
    ---------------------------------------------
    生活的意义并不是与他人争高下,而在于享受努力实现目标的过程,结果是对自己行动的嘉奖。
    ↑面的话,越看越不痛快,应该这么说:

    生活的意义就是你自己知道你要做什么,明确目标。没有目标,后面都是瞎扯!
  • 相关阅读:
    Discuz!NT 系统架构分析
    jquery pager
    Nhibernate分页方法
    Discuz nt模板机制
    WTclient创建OPC client方法
    OPC
    Regular Expressions in Java
    How to use VS to manipulate Access
    OPC客户端设计
    How to use VS to manipulate Excel使用MFC读写Excel
  • 原文地址:https://www.cnblogs.com/pengchenggang/p/15424683.html
Copyright © 2011-2022 走看看