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)
            }
          })
         
         },
  • 相关阅读:
    008 同步
    007 优雅的关闭线程
    006 线程中的join方法
    005 线程ID和线程的优先级
    004 后台线程
    003 Thread的构造
    群发 图片和语音失败原因是 ,返回 content是 null,
    状态,
    Shape Of My Heart
    转码 的状态,嘿嘿,小bug,少了一个 !
  • 原文地址:https://www.cnblogs.com/chenlongsheng/p/15348864.html
Copyright © 2011-2022 走看看