zoukankan      html  css  js  c++  java
  • axios和ajax对响应是文件流用blob处理

    先看axios请求处理,下载文件

    this.$axios.get(api.exportMortgageOrderExcelVisit, { params: params, responseType: 'blob'})
                .then(res => {
                  let url = window.URL.createObjectURL(new Blob([res]))
              let link = document.createElement('a')
              link.style.display = 'none'
              link.href = url
              let excelName = '下载文件.xlsx'
              link.setAttribute('download', excelName)
              document.body.appendChild(link)
              link.click()
                })
                .catch(() => {
                  
                })

    ajax请求,文件转换成图片(使用原生ajax,因为jquery没有blob数据格式)

         var xhr = null;
            if(window.XMLHttpRequest) {
              xhr = new XMLHttpRequest();
            } else {
              xhr = new ActiveXObject("Microsoft.XMLHTTP");
            }
    xhr.open(
    "GET",$apiClent.getLoginImgCheckCode,true); xhr.responseType = "blob"; xhr.send(); xhr.onreadystatechange = function(){ if(xhr.readyState == 4 && xhr.status == 200){ console.log(xhr.getResponseHeader('codeNum')) var imgUrl = window.URL.createObjectURL(new Blob([xhr.response])) $('#verification-img').attr('src', imgUrl) } }
  • 相关阅读:
    10uF的电容能滤除什么频率的电源纹波?
    Integrate Logic Analyzer入门
    状态机
    Setup和Hold(Max/Min)分析
    RS232
    Vivado时序分析概念setup time, hold time
    python学习第34天
    python学习第33天
    python学习第32天
    python学习第31天
  • 原文地址:https://www.cnblogs.com/mk2016/p/13566998.html
Copyright © 2011-2022 走看看