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) } }
  • 相关阅读:
    1099. Build A Binary Search Tree (30)
    两个新事物
    time.h
    Nohup命令
    进程锁
    C++中虚析构函数的作用
    c++ 修改stl set中的元素
    STL迭代器辅助函数——advance
    CTreeCtrl 控件使用总结
    关于stl advance函数移动步数超过容器大小(越界)的研究
  • 原文地址:https://www.cnblogs.com/mk2016/p/13566998.html
Copyright © 2011-2022 走看看