• axios 下载文件


    axio请求里必须加  responseType: 'blob' 参数,如下

    //下载文件
    api.download=function(id) {
      return request({
        url: this.baseUrl+'/download/'+id,
        method: 'get',
        params: {},
        responseType: 'blob'
      })
    }
    

      

    返回结果里面要做如下处理

    .then( res => {
      let blob = new Blob([res], {type: res.type})
      let downloadElement = document.createElement('a')
      let 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); //释放blob对象
         
     })
    

      

  • 相关阅读:
    4.2.1 B
    4.1.1 A
    C
    A
    排序(sort qsort)
    晕,
    clipssubviews = clipstobounds
    scrollview once more,滑出来的 刚好等于 上下偏移的,
    关于 层的显示,
    水倒过来,倒过去,穷折腾啊,
  • 原文地址:https://www.cnblogs.com/pangguoming/p/11080854.html
Copyright © 2020-2023  润新知