zoukankan      html  css  js  c++  java
  • 导出功能

    前提:后台返回二进制文件数据、axios、Blob、ES6

    浏览器兼容:FF/IE10/IE11/CHROME

    代码:

    import axios from 'axios'

    let axio = axios.create({

      headers: {

        'Content-Type': 'application/json;charset=utf-8'

     },

     responseType:'blob' //返回数据的格式为blob

    })

    axio({

      url: 后端api,

      method: 'get/post',

      params/data: 参数

    }).then(res => {

      let blob = new Blob([res.data],{type:'要导出文件类型MIME类型'})

      if('msSaveOrOpenBlob' in navigator){

        window.navigator.msSaveOrOpen(blob,'***')

     }else{

       let downElement = document.createElement('a')

       let url = window.URL.createObjectURL(blob)

       downElement.href = url

       downElement.download = '***文件名称***'

       document.body.appendChild(downElement)

       downElement.click()

       document.body.removeChild(downElement)

       window.URL.revokeObjectURL(url)

    }

    感慨一下:MDN/MSDN是个好网站~

  • 相关阅读:
    淘宝网站
    CentOS 安装 gcc
    待整理
    待整理
    CentOS常用查看系统命令
    Oracle 分区字段数据更新
    MapReduce修改输出的文件名
    MapReduce分区的使用(Partition)
    使用JobControl控制MapReduce任务
    Centos安装ntfs
  • 原文地址:https://www.cnblogs.com/respect2017/p/9234508.html
Copyright © 2011-2022 走看看