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

     
    import vue from 'vue'
    import { ACCESS_TOKEN } from '@admin/store/mutation-types'
    import {cloneDeep} from 'lodash'
    import axios from 'axios'
    import downloader from 'downloadjs'
     
     
     
     downList(type){
           let param={
            type: type
             }
          axios({
            method: 'get',
            url: process.env.VUE_APP_BASE_API + '/speed-progress/selectExcl',
            params:param,
            headers: {
              'Content-Type': 'application/x-www-form-urlencoded',
              'X-Access-Token': vue.ls.get(ACCESS_TOKEN),
            },
             responseType:"blob"
          }).then((res) => {
            console.log(res)
            const fileName = res.headers['content-disposition']
              ? window.decodeURI( res.headers['content-disposition'].split('=')[1],  'UTF-8',  )  : 'data.csv'
                 const extension = fileName.split('.')[1]
            if(extension == 'csv'){
             downloader(res.data, fileName)
            }
            else{
              downloader(new Blob([res.data], {type: 'application/' + extension}), fileName)
            }
          })
         
         },
  • 相关阅读:
    排序算法-总览
    MySQL插入大批量测试数据
    【剑指offer】面试的流程
    并发编程-内置锁
    并发编程-使用线程安全类
    规约先行-(二十一)设计规约
    规约先行-(二十)服务器
    [转]web.xml什么时候被加载进内存的
    DOM和BOM的理解
    代理&反向代理
  • 原文地址:https://www.cnblogs.com/chenlongsheng/p/15348864.html
Copyright © 2011-2022 走看看